"use strict";(()=>{var e={};e.id=796,e.ids=[796],e.modules={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")},97956:(e,t,n)=>{n.r(t),n.d(t,{originalPathname:()=>g,patchFetch:()=>h,requestAsyncStorage:()=>l,routeModule:()=>d,serverHooks:()=>c,staticGenerationAsyncStorage:()=>m});var r={};n.r(r),n.d(r,{POST:()=>p});var o=n(49303),i=n(88716),a=n(60670),s=n(87070),u=n(8194);async function p(e){try{let{tenantSlug:t,storeSlug:r,items:o}=await e.json();if(!t||!r||!o?.length)return s.NextResponse.json({promotion:null});let i=await u._.tenant.findUnique({where:{slug:t}});if(!i)return s.NextResponse.json({promotion:null});let a=await u._.store.findFirst({where:{tenantId:i.id,slug:r}});if(!a)return s.NextResponse.json({promotion:null});let p=o.map(e=>e.menuItemId),d=await u._.menuItem.findMany({where:{id:{in:p}},select:{id:!0,categoryId:!0}}),l=new Map(d.map(e=>[e.id,e.categoryId])),m=o.map(e=>({menuItemId:e.menuItemId,categoryId:l.get(e.menuItemId)||"",quantity:e.quantity,unitPrice:e.unitPrice,subtotal:e.unitPrice*e.quantity})),c=m.reduce((e,t)=>e+t.subtotal,0),{detectHappyHour:g,detectBundle:h}=await n.e(8347).then(n.bind(n,48347)),I={tenantId:i.id,storeId:a.id,items:m,subtotal:c},[x,P]=await Promise.all([g(I),h(I)]),w=null;return w=x&&P?x.discountAmount>=P.discountAmount?x:P:x||P||null,s.NextResponse.json({promotion:w})}catch(e){return console.error("Promo detect error:",e),s.NextResponse.json({promotion:null})}}let d=new o.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/public/promotions/detect/route",pathname:"/api/public/promotions/detect",filename:"route",bundlePath:"app/api/public/promotions/detect/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\public\\promotions\\detect\\route.ts",nextConfigOutput:"",userland:r}),{requestAsyncStorage:l,staticGenerationAsyncStorage:m,serverHooks:c}=d,g="/api/public/promotions/detect/route";function h(){return(0,a.patchFetch)({serverHooks:c,staticGenerationAsyncStorage:m})}},8194:(e,t,n)=>{n.d(t,{_:()=>o});let r=require("@prisma/client"),o=globalThis.prisma??new r.PrismaClient}};var t=require("../../../../../webpack-runtime.js");t.C(e);var n=e=>t(t.s=e),r=t.X(0,[8948,5972],()=>n(97956));module.exports=r})();