"use strict";(()=>{var e={};e.id=8654,e.ids=[8654],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")},27497:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>f,requestAsyncStorage:()=>p,routeModule:()=>l,serverHooks:()=>w,staticGenerationAsyncStorage:()=>m});var a={};r.r(a),r.d(a,{GET:()=>c});var s=r(49303),n=r(88716),i=r(60670),d=r(87070),o=r(8194),u=r(73218);async function c(){try{let{superAdmin:e,error:t}=await (0,u.WC)("dashboard:read");if(t)return t;let r=new Date,a=new Date(r.getFullYear(),r.getMonth(),1),[s,n,i,c,l,p,m,w]=await Promise.all([o._.tenant.count(),o._.tenant.count({where:{isActive:!0}}),o._.subscription.aggregate({where:{status:"active"},_sum:{amount:!0}}),o._.ticket.count({where:{status:"open"}}),o._.subscription.count({where:{status:"active"}}),o._.tenant.count({where:{createdAt:{gte:a}}}),o._.tenant.findMany({take:5,orderBy:{createdAt:"desc"},include:{subscriptions:{take:1,orderBy:{createdAt:"desc"},include:{plan:!0}}}}),o._.ticket.findMany({where:{status:"open"},take:5,orderBy:{createdAt:"desc"},include:{tenant:{select:{name:!0}}}})]);return d.NextResponse.json({stats:{totalTenants:s,activeTenants:n,totalRevenue:Number(i._sum.amount||0),openTickets:c,activeSubscriptions:l,newTenantsThisMonth:p},recentTenants:m,recentTickets:w})}catch(e){return console.error("Super admin dashboard error:",e),d.NextResponse.json({error:"Terjadi kesalahan server"},{status:500})}}let l=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/superadmin/dashboard/route",pathname:"/api/superadmin/dashboard",filename:"route",bundlePath:"app/api/superadmin/dashboard/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\superadmin\\dashboard\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:w}=l,h="/api/superadmin/dashboard/route";function f(){return(0,i.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:m})}},8194:(e,t,r)=>{r.d(t,{_:()=>s});let a=require("@prisma/client"),s=globalThis.prisma??new a.PrismaClient},73218:(e,t,r)=>{r.d(t,{KV:()=>l,TM:()=>c,WC:()=>p});var a=r(41482),s=r.n(a),n=r(71615),i=r(87070),d=r(8194),o=r(579);let u=process.env.JWT_SECRET||"fallback-secret-change-me";function c(e){return s().sign({...e,isSuperAdmin:!0},u,{expiresIn:"7d"})}async function l(){let e=await (0,n.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 a=await d._.superAdmin.findUnique({where:{id:r.superAdminId}});return a&&a.isActive?a:null}async function p(e){let t=await l();return t?(0,o.Fs)(t.role,e)?{superAdmin:t,error:null}:{superAdmin:null,error:i.NextResponse.json({error:"Anda tidak memiliki akses untuk fitur ini"},{status:403})}:{superAdmin:null,error:i.NextResponse.json({error:"Tidak terautentikasi"},{status:401})}}},579:(e,t,r)=>{r.d(t,{Fs:()=>n,j$:()=>a});let a=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 n(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),a=t.X(0,[8948,5972,4261],()=>r(27497));module.exports=a})();