"use strict";(()=>{var e={};e.id=199,e.ids=[199],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")},84719:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>y,patchFetch:()=>h,requestAsyncStorage:()=>m,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>x});var a={};r.r(a),r.d(a,{GET:()=>d});var n=r(49303),s=r(88716),o=r(60670),i=r(87070),u=r(8194),c=r(95456),l=r(45239);async function d(e){try{let t=await (0,c.ts)();if(!t)return i.NextResponse.json({error:"Unauthorized"},{status:401});if(!(0,c.MH)(t.role,["owner","admin","manager"]))return i.NextResponse.json({error:"Forbidden"},{status:403});let r=await (0,l.F)(t.tenantId,"loyalty");if(r)return r;let a=parseInt(e.nextUrl.searchParams.get("page")||"1"),n=parseInt(e.nextUrl.searchParams.get("limit")||"20"),s=e.nextUrl.searchParams.get("type"),o=e.nextUrl.searchParams.get("customerId"),d=(a-1)*n,p={tenantId:t.tenantId};s&&["earn","redeem","adjust"].includes(s)&&(p.type=s),o&&(p.customerId=o);let[m,x]=await Promise.all([u._.loyaltyTransaction.findMany({where:p,include:{customer:{select:{name:!0,phone:!0}},order:{select:{orderNumber:!0}}},orderBy:{createdAt:"desc"},take:n,skip:d}),u._.loyaltyTransaction.count({where:p})]);return i.NextResponse.json({transactions:m,pagination:{page:a,limit:n,total:x,totalPages:Math.ceil(x/n)}})}catch{return i.NextResponse.json({error:"Server error"},{status:500})}}let p=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/loyalty/transactions/route",pathname:"/api/loyalty/transactions",filename:"route",bundlePath:"app/api/loyalty/transactions/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\loyalty\\transactions\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:m,staticGenerationAsyncStorage:x,serverHooks:f}=p,y="/api/loyalty/transactions/route";function h(){return(0,o.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:x})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>d,MH:()=>f,PT:()=>y,RA:()=>p,WX:()=>m,c_:()=>l,ts:()=>x});var a=r(41482),n=r.n(a),s=r(42023),o=r.n(s),i=r(71615),u=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function l(e){return o().hash(e,12)}async function d(e,t){return o().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,i.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 y(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:()=>o,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,o=0;switch(t){case"stores":s=await a._.store.count({where:{tenantId:e,isActive:!0}}),o=r.maxStores;break;case"staff":s=await a._.user.count({where:{tenantId:e,isActive:!0}}),o=r.maxStaff;break;case"menuItems":s=await a._.menuItem.count({where:{tenantId:e,isActive:!0}}),o=r.maxMenuItems;break;case"orders":let i=new Date;i.setDate(1),i.setHours(0,0,0,0),s=await a._.order.count({where:{tenantId:e,createdAt:{gte:i}}}),o=r.maxOrders}return 0===o?{allowed:!0,current:s,max:o}:{allowed:s<o,current:s,max:o}}function o(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(84719));module.exports=a})();