"use strict";(()=>{var e={};e.id=9684,e.ids=[9684],e.modules={53524:e=>{e.exports=require("@prisma/client")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},72554:(e,r,t)=>{t.r(r),t.d(r,{headerHooks:()=>P,originalPathname:()=>h,requestAsyncStorage:()=>l,routeModule:()=>p,serverHooks:()=>m,staticGenerationAsyncStorage:()=>g,staticGenerationBailout:()=>E});var a={};t.r(a),t.d(a,{GET:()=>c,POST:()=>u}),t(95655);var s=t(83323),o=t(54647),n=t(66886),i=t(30953);async function c(e){try{let{searchParams:r}=new URL(e.url),t=r.get("category"),a=r.get("featured"),s=r.get("search"),o=r.get("minPrice"),c=r.get("maxPrice"),u=r.get("stock"),d=r.get("sort")||"newest",p=parseInt(r.get("skip")||"0"),l=parseInt(r.get("take")||"9"),g={},m=[];t&&"all"!==t&&m.push({OR:[{category:t},{categoryId:t},{categoryRef:{slug:t}}]}),"true"===a&&(g.featured=!0),s&&m.push({OR:[{nameEn:{contains:s}},{nameFr:{contains:s}},{descriptionEn:{contains:s}},{sku:{contains:s}}]}),(o||c)&&(g.price={},o&&(g.price.gte=parseFloat(o)),c&&(g.price.lte=parseFloat(c))),"true"===u&&(g.stockStatus="In Stock"),m.length>0&&(g.AND=m);let P={createdAt:"desc"};switch(d){case"price_asc":P={price:"asc"};break;case"price_desc":P={price:"desc"};break;case"name_asc":P={nameEn:"asc"};break;default:P={createdAt:"desc"}}let[E,h]=await Promise.all([i._.product.findMany({where:g,orderBy:P,skip:p,take:l,select:{id:!0,slug:!0,nameEn:!0,nameFr:!0,descriptionEn:!0,descriptionFr:!0,category:!0,categoryId:!0,image:!0,price:!0,unit:!0,minOrder:!0,origin:!0,sku:!0,stockStatus:!0,featured:!0,variants:{select:{id:!0,size:!0,sku:!0}},categoryRef:{select:{id:!0,slug:!0,nameEn:!0,nameFr:!0}}}}),i._.product.count({where:g})]);return n.Z.json({data:E,total:h},{headers:{"Cache-Control":"s-maxage=30, stale-while-revalidate=120"}})}catch(e){return console.error("Error fetching products:",e),n.Z.json({error:"Error fetching products"},{status:500})}}async function u(e){try{let r=await e.json(),{nameEn:t,nameFr:a,slug:s,descriptionEn:o,descriptionFr:c,seoTitle:u,seoDescription:d,category:p,categoryId:l,image:g,gallery:m,unit:P,minOrder:E,origin:h,sku:A,stockStatus:f,dimensions:k,weight:y,featured:v,price:_,variants:w}=r,x=w?.map(e=>e.id.startsWith("new-")?{...e,id:crypto.randomUUID()}:e)||[],R=s||t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)+/g,""),S=await i._.product.create({data:{nameEn:t,nameFr:a,slug:R,descriptionEn:o,descriptionFr:c,seoTitle:u,seoDescription:d,category:p,categoryId:l||void 0,image:g,gallery:m||void 0,unit:P,minOrder:E,origin:h,sku:A,stockStatus:f,dimensions:k,weight:y,featured:v,price:_?Number(_):0,variants:{create:x.map(e=>({id:e.id,size:e.size,sku:e.sku}))}},include:{variants:!0}});return n.Z.json(S)}catch(e){return console.error("Error creating product:",e),n.Z.json({error:"Error creating product"},{status:500})}}let d=s.AppRouteRouteModule,p=new d({definition:{kind:o.x.APP_ROUTE,page:"/api/products/route",pathname:"/api/products",filename:"route",bundlePath:"app/api/products/route"},resolvedPagePath:"D:\\Code\\MusaFoods_New\\musafoods\\app\\api\\products\\route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:l,staticGenerationAsyncStorage:g,serverHooks:m,headerHooks:P,staticGenerationBailout:E}=p,h="/api/products/route"},30953:(e,r,t)=>{t.d(r,{_:()=>o});var a=t(53524);let s=globalThis,o=s.prisma??new a.PrismaClient},54647:(e,r)=>{var t;Object.defineProperty(r,"x",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(t||(t={}))}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[9727,3497,6886],()=>t(72554));module.exports=a})();