"use strict";(()=>{var e={};e.id=8996,e.ids=[8996],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")},17766:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>h,requestAsyncStorage:()=>c,routeModule:()=>l,serverHooks:()=>w,staticGenerationAsyncStorage:()=>m});var i={};r.r(i),r.d(i,{PUT:()=>p});var s=r(49303),a=r(88716),n=r(60670),d=r(87070),o=r(8194),u=r(73218);async function p(e,{params:t}){try{let{superAdmin:r,error:i}=await (0,u.WC)("subscriptions:write");if(i)return i;let{id:s}=await t,a=await e.json();if(!await o._.subscription.findUnique({where:{id:s}}))return d.NextResponse.json({error:"Langganan tidak ditemukan"},{status:404});let{planId:n,status:p,endDate:l,billingCycle:c,amount:m}=a,w={};if(void 0!==n){if(!await o._.plan.findUnique({where:{id:n}}))return d.NextResponse.json({error:"Paket tidak ditemukan"},{status:400});w.planId=n}void 0!==p&&(w.status=p),void 0!==l&&(w.endDate=new Date(l)),void 0!==c&&(w.billingCycle=c),void 0!==m&&(w.amount=m);let f=await o._.subscription.update({where:{id:s},data:w,include:{tenant:{select:{id:!0,name:!0}},plan:{select:{id:!0,name:!0}}}});return d.NextResponse.json({subscription:f})}catch(e){return console.error("Update subscription error:",e),d.NextResponse.json({error:"Terjadi kesalahan server"},{status:500})}}let l=new s.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/superadmin/subscriptions/[id]/route",pathname:"/api/superadmin/subscriptions/[id]",filename:"route",bundlePath:"app/api/superadmin/subscriptions/[id]/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\superadmin\\subscriptions\\[id]\\route.ts",nextConfigOutput:"",userland:i}),{requestAsyncStorage:c,staticGenerationAsyncStorage:m,serverHooks:w}=l,f="/api/superadmin/subscriptions/[id]/route";function h(){return(0,n.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:m})}},8194:(e,t,r)=>{r.d(t,{_:()=>s});let i=require("@prisma/client"),s=globalThis.prisma??new i.PrismaClient},73218:(e,t,r)=>{r.d(t,{KV:()=>l,TM:()=>p,WC:()=>c});var i=r(41482),s=r.n(i),a=r(71615),n=r(87070),d=r(8194),o=r(579);let u=process.env.JWT_SECRET||"fallback-secret-change-me";function p(e){return s().sign({...e,isSuperAdmin:!0},u,{expiresIn:"7d"})}async function l(){let e=await (0,a.cookies)(),t=e.get("sa_token")?.value;if(!t)return null;let r=function(e){try{let t=s().verify(e,u);if(!t.isSuperAdmin)return null;return t}catch{return null}}(t);if(!r)return null;let i=await d._.superAdmin.findUnique({where:{id:r.superAdminId}});return i&&i.isActive?i:null}async function c(e){let t=await l();return t?(0,o.Fs)(t.role,e)?{superAdmin:t,error:null}:{superAdmin:null,error:n.NextResponse.json({error:"Anda tidak memiliki akses untuk fitur ini"},{status:403})}:{superAdmin:null,error:n.NextResponse.json({error:"Tidak terautentikasi"},{status:401})}}},579:(e,t,r)=>{r.d(t,{Fs:()=>a,j$:()=>i});let i=Object.values({SUPERADMIN:"superadmin",ADMIN:"admin",FINANCE:"finance",SUPPORT:"support",CONTENT:"content",VIEWER:"viewer"}),s={superadmin:["dashboard:read","plans:read","plans:write","tenants:read","tenants:write","subscriptions:read","subscriptions:write","payment_settings:read","payment_settings:write","withdrawals:read","withdrawals:write","tickets:read","tickets:write","cms:read","cms:write","staff:read","staff:write","affiliates:read","affiliates:write","email_settings:read","email_settings:write"],admin:["dashboard:read","plans:read","plans:write","tenants:read","tenants:write","subscriptions:read","subscriptions:write","payment_settings:read","payment_settings:write","withdrawals:read","withdrawals:write","tickets:read","tickets:write","cms:read","cms:write","affiliates:read","affiliates:write","email_settings:read","email_settings:write"],finance:["dashboard:read","subscriptions:read","payment_settings:read","payment_settings:write","withdrawals:read","withdrawals:write","affiliates:read"],support:["dashboard:read","tenants:read","tickets:read","tickets:write"],content:["dashboard:read","cms:read","cms:write"],viewer:["dashboard:read"]};function a(e,t){let r=s[e];return!!r&&r.includes(t)}}};var t=require("../../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),i=t.X(0,[8948,5972,4261],()=>r(17766));module.exports=i})();