"use strict";(()=>{var e={};e.id=9157,e.ids=[9157],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")},44982:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>y,requestAsyncStorage:()=>m,routeModule:()=>c,serverHooks:()=>f,staticGenerationAsyncStorage:()=>l});var a={};r.r(a),r.d(a,{GET:()=>d});var s=r(49303),i=r(88716),n=r(60670),o=r(87070),u=r(8194),p=r(15230);async function d(e){try{let t=e.nextUrl.searchParams.get("tenantSlug"),r=e.nextUrl.searchParams.get("storeSlug");if(!t||!r)return o.NextResponse.json({error:"tenantSlug dan storeSlug wajib diisi"},{status:400});let a=await u._.tenant.findUnique({where:{slug:t}});if(!a||!a.isActive)return o.NextResponse.json({error:"Restoran tidak ditemukan"},{status:404});let s=await (0,p.p6)(a.id);if(!(0,p.U6)(s.features,"promos"))return o.NextResponse.json({error:"Fitur promo tidak tersedia"},{status:403});let i=await u._.store.findFirst({where:{tenantId:a.id,slug:r,isActive:!0}});if(!i)return o.NextResponse.json({error:"Cabang tidak ditemukan"},{status:404});let n=new Date,d=await u._.promotion.findMany({where:{tenantId:a.id,type:{in:["happy_hour","bundle"]},isActive:!0,startDate:{lte:n},endDate:{gte:n}},include:{storeLinks:{select:{storeId:!0}}}}),c=n.getHours().toString().padStart(2,"0")+":"+n.getMinutes().toString().padStart(2,"0"),m=n.getDay(),l=d.filter(e=>{if(e.storeLinks.length>0&&!e.storeLinks.some(e=>e.storeId===i.id))return!1;if("happy_hour"===e.type){if(e.startTime&&e.endTime&&(c<e.startTime||c>e.endTime))return!1;if(e.daysOfWeek)try{if(!JSON.parse(e.daysOfWeek).includes(m))return!1}catch{return!1}}return!0}).map(e=>({id:e.id,type:e.type,name:e.name,description:e.description,discountType:e.discountType,discountValue:e.discountValue,startTime:e.startTime,endTime:e.endTime,daysOfWeek:e.daysOfWeek,buyQuantity:e.buyQuantity,getQuantity:e.getQuantity}));return o.NextResponse.json({promotions:l})}catch{return o.NextResponse.json({error:"Internal server error"},{status:500})}}let c=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/public/promotions/active/route",pathname:"/api/public/promotions/active",filename:"route",bundlePath:"app/api/public/promotions/active/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\public\\promotions\\active\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:m,staticGenerationAsyncStorage:l,serverHooks:f}=c,x="/api/public/promotions/active/route";function y(){return(0,n.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:l})}},8194:(e,t,r)=>{r.d(t,{_:()=>s});let a=require("@prisma/client"),s=globalThis.prisma??new a.PrismaClient},15230:(e,t,r)=>{r.d(t,{MN:()=>i,U6:()=>n,p6:()=>s});var a=r(8194);async function s(e){let t=await a._.subscription.findFirst({where:{tenantId:e,status:{in:["active","trial"]}},include:{plan:!0},orderBy:{createdAt:"desc"}});return t?{maxStores:t.plan.maxStores,maxStaff:t.plan.maxStaff,maxMenuItems:t.plan.maxMenuItems,maxOrders:t.plan.maxOrders,features:JSON.parse(t.plan.features)}:{maxStores:1,maxStaff:3,maxMenuItems:30,maxOrders:100,features:["pos","qr_menu"]}}async function i(e,t){let r=await s(e),i=0,n=0;switch(t){case"stores":i=await a._.store.count({where:{tenantId:e,isActive:!0}}),n=r.maxStores;break;case"staff":i=await a._.user.count({where:{tenantId:e,isActive:!0}}),n=r.maxStaff;break;case"menuItems":i=await a._.menuItem.count({where:{tenantId:e,isActive:!0}}),n=r.maxMenuItems;break;case"orders":let o=new Date;o.setDate(1),o.setHours(0,0,0,0),i=await a._.order.count({where:{tenantId:e,createdAt:{gte:o}}}),n=r.maxOrders}return 0===n?{allowed:!0,current:i,max:n}:{allowed:i<n,current:i,max:n}}function n(e,t){return e.includes(t)}}};var t=require("../../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[8948,5972],()=>r(44982));module.exports=a})();