"use strict";(()=>{var e={};e.id=613,e.ids=[613],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")},41896:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>h,requestAsyncStorage:()=>f,routeModule:()=>d,serverHooks:()=>p,staticGenerationAsyncStorage:()=>m});var a={};r.r(a),r.d(a,{GET:()=>c});var i=r(49303),n=r(88716),s=r(60670),o=r(87070),u=r(39655),l=r(8194);async function c(){try{let e=await (0,u.Of)();if(!e)return o.NextResponse.json({error:"Unauthorized"},{status:401});let[t,r,a,i,n]=await Promise.all([l._.tenant.count({where:{affiliateId:e.id}}),l._.tenant.count({where:{affiliateId:e.id,isActive:!0,plan:{not:"free"}}}),l._.affiliateCommission.aggregate({where:{affiliateId:e.id,status:"credited"},_sum:{commissionAmount:!0}}),l._.affiliateWallet.findUnique({where:{affiliateId:e.id}}),l._.affiliateCommission.findMany({where:{affiliateId:e.id},include:{tenant:{select:{name:!0}}},orderBy:{createdAt:"desc"},take:5})]);return o.NextResponse.json({stats:{totalReferrals:t,activeReferrals:r,totalCommission:Number(a._sum.commissionAmount||0),walletBalance:Number(i?.balance||0)},recentCommissions:n.map(e=>({id:e.id,tenantName:e.tenant.name,commissionAmount:Number(e.commissionAmount),commissionRate:Number(e.commissionRate),status:e.status,createdAt:e.createdAt})),referralCode:e.referralCode,isActive:e.isActive})}catch(e){return console.error("Affiliate dashboard error:",e),o.NextResponse.json({error:"Server error"},{status:500})}}let d=new i.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/affiliate/dashboard/route",pathname:"/api/affiliate/dashboard",filename:"route",bundlePath:"app/api/affiliate/dashboard/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\affiliate\\dashboard\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:f,staticGenerationAsyncStorage:m,serverHooks:p}=d,x="/api/affiliate/dashboard/route";function h(){return(0,s.patchFetch)({serverHooks:p,staticGenerationAsyncStorage:m})}},39655:(e,t,r)=>{r.d(t,{No:()=>l,Of:()=>c,PX:()=>u});var a=r(41482),i=r.n(a),n=r(71615),s=r(8194);let o=process.env.JWT_SECRET||"fallback-secret-change-me";function u(e){return i().sign({...e,isAffiliate:!0},o,{expiresIn:"7d"})}async function l(){let e=await (0,n.cookies)(),t=e.get("aff_token")?.value;if(!t)return null;let r=function(e){try{let t=i().verify(e,o);if(!t.isAffiliate)return null;return t}catch{return null}}(t);return r&&await s._.affiliate.findUnique({where:{id:r.affiliateId}})||null}async function c(){return await l()||null}},8194:(e,t,r)=>{r.d(t,{_:()=>i});let a=require("@prisma/client"),i=globalThis.prisma??new a.PrismaClient}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[8948,5972,4261],()=>r(41896));module.exports=a})();