"use strict";(()=>{var e={};e.id=1089,e.ids=[1089],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")},15520:(e,t,n)=>{n.r(t),n.d(t,{originalPathname:()=>f,patchFetch:()=>g,requestAsyncStorage:()=>d,routeModule:()=>p,serverHooks:()=>x,staticGenerationAsyncStorage:()=>m});var r={};n.r(r),n.d(r,{GET:()=>l});var a=n(49303),s=n(88716),i=n(60670),u=n(87070),o=n(8194),c=n(95456);async function l(){try{let e=await (0,c.ts)();if(!e)return u.NextResponse.json({error:"Anda belum login"},{status:401});let t=await o._.subscription.findFirst({where:{tenantId:e.tenantId,status:"active"},include:{plan:!0},orderBy:{createdAt:"desc"}}),[n,r,a,s]=await Promise.all([o._.store.count({where:{tenantId:e.tenantId,isActive:!0}}),o._.user.count({where:{tenantId:e.tenantId,isActive:!0}}),o._.menuItem.count({where:{tenantId:e.tenantId,isActive:!0}}),o._.order.count({where:{tenantId:e.tenantId,createdAt:{gte:new Date(new Date().getFullYear(),new Date().getMonth(),1)}}})]),i=[];if(t?.plan?.features)try{i=JSON.parse(t.plan.features)}catch{i=[]}return u.NextResponse.json({subscription:t?{id:t.id,status:t.status,startDate:t.startDate,endDate:t.endDate,trialEndDate:t.trialEndDate,billingCycle:t.billingCycle,amount:Number(t.amount),plan:{id:t.plan.id,name:t.plan.name,slug:t.plan.slug,description:t.plan.description,price:Number(t.plan.price),yearlyPrice:Number(t.plan.yearlyPrice),currency:t.plan.currency,features:i,isPopular:t.plan.isPopular}}:null,usage:{stores:n,staff:r,menuItems:a,ordersThisMonth:s},limits:t?{maxStores:t.plan.maxStores,maxStaff:t.plan.maxStaff,maxMenuItems:t.plan.maxMenuItems,maxOrders:t.plan.maxOrders}:null})}catch{return u.NextResponse.json({error:"Terjadi kesalahan server"},{status:500})}}let p=new a.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/tenant/subscription/route",pathname:"/api/tenant/subscription",filename:"route",bundlePath:"app/api/tenant/subscription/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\tenant\\subscription\\route.ts",nextConfigOutput:"",userland:r}),{requestAsyncStorage:d,staticGenerationAsyncStorage:m,serverHooks:x}=p,f="/api/tenant/subscription/route";function g(){return(0,i.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:m})}},95456:(e,t,n)=>{n.d(t,{Gv:()=>p,MH:()=>f,PT:()=>g,RA:()=>d,WX:()=>m,c_:()=>l,ts:()=>x});var r=n(41482),a=n.n(r),s=n(42023),i=n.n(s),u=n(71615),o=n(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function l(e){return i().hash(e,12)}async function p(e,t){return i().compare(e,t)}function d(e){return a().sign(e,c,{expiresIn:"7d"})}function m(e){try{return a().verify(e,c)}catch{return null}}async function x(){let e=await (0,u.cookies)(),t=e.get("token")?.value;if(!t)return null;let n=m(t);return n?await o._.user.findUnique({where:{id:n.userId},include:{tenant:!0,store:!0}}):null}function f(e,t){return t.includes(e)}function g(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,n)=>{n.d(t,{_:()=>a});let r=require("@prisma/client"),a=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,4261,2023],()=>n(15520));module.exports=r})();