"use strict";(()=>{var e={};e.id=986,e.ids=[986],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")},43763:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>v,patchFetch:()=>w,requestAsyncStorage:()=>h,routeModule:()=>g,serverHooks:()=>x,staticGenerationAsyncStorage:()=>y});var s={};t.r(s),t.d(s,{GET:()=>d,POST:()=>m,dynamic:()=>p});var a=t(49303),i=t(88716),o=t(60670),n=t(87070),l=t(75571),u=t(90455),c=t(72331);let p="force-dynamic";async function d(e){try{let{searchParams:r}=new URL(e.url),t=parseInt(r?.get("page")??"1"),s=parseInt(r?.get("perPage")??"20"),a=r?.get("status"),i=r?.get("search"),o={};a&&"ALL"!==a&&(o.status=a),i&&(o.OR=[{title:{contains:i,mode:"insensitive"}},{make:{contains:i,mode:"insensitive"}},{model:{contains:i,mode:"insensitive"}}]);let[l,u]=await Promise.all([c._.vehicle.findMany({where:o,include:{images:{orderBy:{order:"asc"}},category:!0},orderBy:{createdAt:"desc"},skip:(t-1)*s,take:s}),c._.vehicle.count({where:o})]);return n.NextResponse.json({vehicles:l??[],total:u??0,page:t,perPage:s})}catch(e){return console.error("Vehicles GET error:",e),n.NextResponse.json({error:"Failed to fetch"},{status:500})}}async function m(e){try{if(!await (0,l.getServerSession)(u.L))return n.NextResponse.json({error:"Unauthorized"},{status:401});let r=await e.json(),t=`${r?.make??"equipo"}-${r?.model??"unknown"}-${r?.year??2024}-${Date.now()}`.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-"),s=await c._.vehicle.create({data:{title:r?.title??`${r?.make??""} ${r?.model??""} ${r?.year??""}`.trim(),slug:t,description:r?.description??null,make:r?.make??"",model:r?.model??"",year:parseInt(r?.year??"2024"),price:parseFloat(r?.price??"0"),mileage:r?.mileage?parseInt(r.mileage):null,engineType:r?.engineType??null,transmission:r?.transmission??null,fuelType:r?.fuelType??null,horsepower:r?.horsepower??null,color:r?.color??null,vin:r?.vin??null,stockNumber:r?.stockNumber??null,condition:r?.condition??"Used",status:r?.status??"AVAILABLE",featured:r?.featured??!1,categoryId:r?.categoryId??"",images:r?.images?{create:(r.images??[])?.map((e,r)=>({cloudStoragePath:e?.cloudStoragePath??"",isPublic:e?.isPublic??!0,url:e?.url??"",alt:e?.alt??"",order:r,isPrimary:0===r}))}:void 0},include:{images:!0,category:!0}});return n.NextResponse.json(s)}catch(e){return console.error("Vehicle create error:",e),n.NextResponse.json({error:"Failed to create vehicle"},{status:500})}}let g=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/vehicles/route",pathname:"/api/vehicles",filename:"route",bundlePath:"app/api/vehicles/route"},resolvedPagePath:"/Users/jarolsanchez/Desktop/evotrucks/nextjs_space/app/api/vehicles/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:h,staticGenerationAsyncStorage:y,serverHooks:x}=g,v="/api/vehicles/route";function w(){return(0,o.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:y})}},90455:(e,r,t)=>{t.d(r,{L:()=>n});var s=t(53797),a=t(42023),i=t.n(a),o=t(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 r=await o._.user.findUnique({where:{email:e.email}});if(!r||!await i().compare(e.password,r.password))return null;return{id:r.id,email:r.email,name:r.name,role:r.role}}catch{return null}}})],session:{strategy:"jwt"},callbacks:{jwt:async({token:e,user:r})=>(r&&(e.role=r?.role,e.id=r?.id),e),session:async({session:e,token:r})=>(e?.user&&(e.user.role=r?.role,e.user.id=r?.id),e)},pages:{signIn:"/admin/login"},secret:process.env.NEXTAUTH_SECRET}},72331:(e,r,t)=>{t.d(r,{_:()=>a});var s=t(53524);let a=globalThis.prisma||new s.PrismaClient}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[948,598,70,790],()=>t(43763));module.exports=s})();