"use strict";(()=>{var e={};e.id=5315,e.ids=[5315],e.modules={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")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},76162:e=>{e.exports=require("stream")},21764:e=>{e.exports=require("util")},30821:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>w,patchFetch:()=>h,requestAsyncStorage:()=>m,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>x});var a={};r.r(a),r.d(a,{GET:()=>l});var n=r(49303),s=r(88716),i=r(60670),o=r(87070),u=r(8194),c=r(95456),d=r(45239);async function l(e,{params:t}){try{let r=await (0,c.ts)();if(!r)return o.NextResponse.json({error:"Unauthorized"},{status:401});if(!(0,c.MH)(r.role,["owner","admin","manager"]))return o.NextResponse.json({error:"Forbidden"},{status:403});let a=await (0,d.F)(r.tenantId,"customers");if(a)return a;let{id:n}=await t;if(!await u._.customer.findFirst({where:{id:n,tenantId:r.tenantId,isActive:!0}}))return o.NextResponse.json({error:"Pelanggan tidak ditemukan"},{status:404});let s=parseInt(e.nextUrl.searchParams.get("page")||"1"),i=parseInt(e.nextUrl.searchParams.get("limit")||"20"),l=(s-1)*i,p={customerId:n,tenantId:r.tenantId},[m,x]=await Promise.all([u._.order.findMany({where:p,include:{store:{select:{name:!0}},items:{include:{menuItem:{select:{name:!0}}}}},orderBy:{createdAt:"desc"},take:i,skip:l}),u._.order.count({where:p})]);return o.NextResponse.json({orders:m,pagination:{page:s,limit:i,total:x,totalPages:Math.ceil(x/i)}})}catch{return o.NextResponse.json({error:"Internal server error"},{status:500})}}let p=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/customers/[id]/orders/route",pathname:"/api/customers/[id]/orders",filename:"route",bundlePath:"app/api/customers/[id]/orders/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\customers\\[id]\\orders\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:m,staticGenerationAsyncStorage:x,serverHooks:f}=p,w="/api/customers/[id]/orders/route";function h(){return(0,i.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:x})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>l,MH:()=>f,PT:()=>w,RA:()=>p,WX:()=>m,c_:()=>d,ts:()=>x});var a=r(41482),n=r.n(a),s=r(42023),i=r.n(s),o=r(71615),u=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function d(e){return i().hash(e,12)}async function l(e,t){return i().compare(e,t)}function p(e){return n().sign(e,c,{expiresIn:"7d"})}function m(e){try{return n().verify(e,c)}catch{return null}}async function x(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=m(t);return r?await u._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function f(e,t){return t.includes(e)}function w(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>n});let a=require("@prisma/client"),n=globalThis.prisma??new a.PrismaClient},45239:(e,t,r)=>{r.d(t,{F:()=>s});var a=r(87070),n=r(15230);async function s(e,t){let r=await (0,n.p6)(e);return(0,n.U6)(r.features,t)?null:a.NextResponse.json({error:"Fitur ini tidak tersedia pada paket Anda. Silakan upgrade."},{status:403})}},15230:(e,t,r)=>{r.d(t,{MN:()=>s,U6:()=>i,p6:()=>n});var a=r(8194);async function n(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 s(e,t){let r=await n(e),s=0,i=0;switch(t){case"stores":s=await a._.store.count({where:{tenantId:e,isActive:!0}}),i=r.maxStores;break;case"staff":s=await a._.user.count({where:{tenantId:e,isActive:!0}}),i=r.maxStaff;break;case"menuItems":s=await a._.menuItem.count({where:{tenantId:e,isActive:!0}}),i=r.maxMenuItems;break;case"orders":let o=new Date;o.setDate(1),o.setHours(0,0,0,0),s=await a._.order.count({where:{tenantId:e,createdAt:{gte:o}}}),i=r.maxOrders}return 0===i?{allowed:!0,current:s,max:i}:{allowed:s<i,current:s,max:i}}function i(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,4261,2023],()=>r(30821));module.exports=a})();