"use strict";(()=>{var e={};e.id=3707,e.ids=[3707],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")},18409:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>g,requestAsyncStorage:()=>p,routeModule:()=>l,serverHooks:()=>h,staticGenerationAsyncStorage:()=>m});var n={};r.r(n),r.d(n,{GET:()=>c});var a=r(49303),s=r(88716),o=r(60670),i=r(87070),u=r(8194),d=r(95456);async function c(){try{let e=await (0,d.ts)();if(!e)return i.NextResponse.json({error:"Unauthorized"},{status:401});let t=new Date;t.setHours(0,0,0,0);let r=new Date(t);r.setDate(r.getDate()+1);let n=e.storeId?{storeId:e.storeId}:{},[a,s,o,c,l,p,m]=await Promise.all([u._.order.count({where:{tenantId:e.tenantId,createdAt:{gte:t,lt:r},...n}}),u._.order.aggregate({where:{tenantId:e.tenantId,createdAt:{gte:t,lt:r},paymentStatus:"paid",...n},_sum:{total:!0}}),u._.menuItem.count({where:{tenantId:e.tenantId,isActive:!0}}),u._.store.count({where:{tenantId:e.tenantId,isActive:!0}}),u._.user.count({where:{tenantId:e.tenantId,isActive:!0}}),u._.order.findMany({where:{tenantId:e.tenantId,...n},include:{store:{select:{name:!0}},table:{select:{number:!0}},items:{include:{menuItem:{select:{name:!0}}}}},orderBy:{createdAt:"desc"},take:5}),u._.order.count({where:{tenantId:e.tenantId,status:{in:["pending","confirmed","preparing"]},...n}})]);return i.NextResponse.json({stats:{todayOrders:a,todayRevenue:Number(s._sum.total||0),totalMenuItems:o,totalStores:c,totalStaff:l,pendingOrders:m},recentOrders:p})}catch(e){return console.error("Dashboard error:",e),i.NextResponse.json({error:"Server error"},{status:500})}}let l=new a.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/dashboard/route",pathname:"/api/dashboard",filename:"route",bundlePath:"app/api/dashboard/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\dashboard\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:h}=l,x="/api/dashboard/route";function g(){return(0,o.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:m})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>l,MH:()=>x,PT:()=>g,RA:()=>p,WX:()=>m,c_:()=>c,ts:()=>h});var n=r(41482),a=r.n(n),s=r(42023),o=r.n(s),i=r(71615),u=r(8194);let d=process.env.JWT_SECRET||"fallback-secret-change-me";async function c(e){return o().hash(e,12)}async function l(e,t){return o().compare(e,t)}function p(e){return a().sign(e,d,{expiresIn:"7d"})}function m(e){try{return a().verify(e,d)}catch{return null}}async function h(){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 x(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,r)=>{r.d(t,{_:()=>a});let n=require("@prisma/client"),a=globalThis.prisma??new n.PrismaClient}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8948,5972,4261,2023],()=>r(18409));module.exports=n})();