"use strict";(()=>{var e={};e.id=704,e.ids=[704],e.modules={53524:e=>{e.exports=require("@prisma/client")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},27790:e=>{e.exports=require("assert")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},17702:e=>{e.exports=require("events")},32615:e=>{e.exports=require("http")},35240:e=>{e.exports=require("https")},86624:e=>{e.exports=require("querystring")},17360:e=>{e.exports=require("url")},21764:e=>{e.exports=require("util")},71568:e=>{e.exports=require("zlib")},46532:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>w,patchFetch:()=>v,requestAsyncStorage:()=>m,routeModule:()=>h,serverHooks:()=>y,staticGenerationAsyncStorage:()=>x});var s={};r.r(s),r.d(s,{GET:()=>p,dynamic:()=>d});var a=r(49303),o=r(88716),i=r(60670),n=r(87070),l=r(75571),u=r(90455),c=r(72331);let d="force-dynamic";async function p(){try{if(!await (0,l.getServerSession)(u.L))return n.NextResponse.json({error:"Unauthorized"},{status:401});let[e,t,r,s,a,o,i,d,p,h,m,x]=await Promise.all([c._.vehicle.count(),c._.vehicle.count({where:{status:"AVAILABLE"}}),c._.vehicle.count({where:{status:"SOLD"}}),c._.vehicle.count({where:{featured:!0}}),c._.lead.count(),c._.lead.count({where:{status:"NEW"}}),c._.lead.count({where:{status:"CONTACTED"}}),c._.category.count(),c._.vehicle.findMany({orderBy:{viewCount:"desc"},take:5,select:{id:!0,title:!0,viewCount:!0,status:!0}}),c._.lead.findMany({orderBy:{createdAt:"desc"},take:5,include:{vehicle:{select:{title:!0}}}}),c._.lead.groupBy({by:["source"],_count:{id:!0}}),c._.$queryRaw`SELECT TO_CHAR("createdAt", 'YYYY-MM') as month, COUNT(*)::int as count FROM "Lead" WHERE "createdAt" >= NOW() - INTERVAL '6 months' GROUP BY month ORDER BY month ASC`]);return n.NextResponse.json({totalVehicles:e??0,availableVehicles:t??0,soldVehicles:r??0,featuredVehicles:s??0,totalLeads:a??0,newLeads:o??0,contactedLeads:i??0,totalCategories:d??0,topViewed:p??[],recentLeads:h??[],leadsBySource:m??[],leadsByMonth:x??[]})}catch(e){return console.error("Stats error:",e),n.NextResponse.json({error:"Failed to fetch stats"},{status:500})}}let h=new a.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/stats/route",pathname:"/api/stats",filename:"route",bundlePath:"app/api/stats/route"},resolvedPagePath:"/Users/jarolsanchez/Desktop/evotrucks/nextjs_space/app/api/stats/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:m,staticGenerationAsyncStorage:x,serverHooks:y}=h,w="/api/stats/route";function v(){return(0,i.patchFetch)({serverHooks:y,staticGenerationAsyncStorage:x})}},90455:(e,t,r)=>{r.d(t,{L:()=>n});var s=r(53797),a=r(42023),o=r.n(a),i=r(72331);let n={providers:[(0,s.Z)({name:"credentials",credentials:{email:{label:"Email",type:"email"},password:{label:"Password",type:"password"}},async authorize(e){if(!e?.email||!e?.password)return null;try{let t=await i._.user.findUnique({where:{email:e.email}});if(!t||!await o().compare(e.password,t.password))return null;return{id:t.id,email:t.email,name:t.name,role:t.role}}catch{return null}}})],session:{strategy:"jwt"},callbacks:{jwt:async({token:e,user:t})=>(t&&(e.role=t?.role,e.id=t?.id),e),session:async({session:e,token:t})=>(e?.user&&(e.user.role=t?.role,e.user.id=t?.id),e)},pages:{signIn:"/admin/login"},secret:process.env.NEXTAUTH_SECRET}},72331:(e,t,r)=>{r.d(t,{_:()=>a});var s=r(53524);let a=globalThis.prisma||new s.PrismaClient}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[948,598,70,790],()=>r(46532));module.exports=s})();