"use strict";(()=>{var e={};e.id=8552,e.ids=[8552],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")},37964:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>A,requestAsyncStorage:()=>p,routeModule:()=>m,serverHooks:()=>g,staticGenerationAsyncStorage:()=>f});var a={};r.r(a),r.d(a,{GET:()=>l});var n=r(49303),s=r(88716),o=r(60670),i=r(87070),u=r(95456),c=r(8194),d=r(45239);async function l(e){try{let t=await (0,u.ts)();if(!t)return i.NextResponse.json({error:"Unauthorized"},{status:401});if(!(0,u.MH)(t.role,["owner","admin","manager"]))return i.NextResponse.json({error:"Forbidden"},{status:403});let r=await (0,d.F)(t.tenantId,"feedback");if(r)return r;let a=e.nextUrl.searchParams.get("storeId"),n=e.nextUrl.searchParams.get("period")||"30d",s=30;"7d"===n&&(s=7),"90d"===n&&(s=90);let o=new Date;o.setDate(o.getDate()-s);let l={tenantId:t.tenantId,createdAt:{gte:o}};t.storeId?l.storeId=t.storeId:a&&(l.storeId=a);let[m,p]=await Promise.all([c._.feedback.aggregate({where:l,_avg:{rating:!0}}),c._.feedback.count({where:l})]),f=m._avg.rating?parseFloat(m._avg.rating.toFixed(2)):0,g=await c._.feedback.groupBy({by:["rating"],where:l,_count:!0}),x=[1,2,3,4,5].map(e=>{let t=g.find(t=>t.rating===e),r=t?t._count:0;return{rating:e,count:r,percentage:p>0?parseFloat((r/p*100).toFixed(1)):0}}),A=t.storeId||a,w=(A?await c._.$queryRaw`
        SELECT
          DATE_FORMAT(createdAt, '%Y-%m') AS month,
          AVG(rating) AS avgRating,
          COUNT(*) AS count
        FROM feedbacks
        WHERE tenantId = ${t.tenantId}
          AND storeId = ${A}
          AND createdAt >= ${o}
        GROUP BY DATE_FORMAT(createdAt, '%Y-%m')
        ORDER BY month ASC
      `:await c._.$queryRaw`
        SELECT
          DATE_FORMAT(createdAt, '%Y-%m') AS month,
          AVG(rating) AS avgRating,
          COUNT(*) AS count
        FROM feedbacks
        WHERE tenantId = ${t.tenantId}
          AND createdAt >= ${o}
        GROUP BY DATE_FORMAT(createdAt, '%Y-%m')
        ORDER BY month ASC
      `).map(e=>({month:e.month,avgRating:parseFloat(Number(e.avgRating).toFixed(2)),count:Number(e.count)})),h=await c._.feedback.findMany({where:{...l,categories:{not:null}},select:{categories:!0}}),R={};for(let e of h)if(e.categories)try{for(let t of JSON.parse(e.categories))R[t]=(R[t]||0)+1}catch{}let v=Object.entries(R).map(([e,t])=>({category:e,count:t})).sort((e,t)=>t.count-e.count);return i.NextResponse.json({averageRating:f,totalCount:p,ratingDistribution:x,monthlyTrend:w,categoryBreakdown:v})}catch{return i.NextResponse.json({error:"Internal server error"},{status:500})}}let m=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/feedback/summary/route",pathname:"/api/feedback/summary",filename:"route",bundlePath:"app/api/feedback/summary/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\feedback\\summary\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:p,staticGenerationAsyncStorage:f,serverHooks:g}=m,x="/api/feedback/summary/route";function A(){return(0,o.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:f})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>l,MH:()=>g,PT:()=>x,RA:()=>m,WX:()=>p,c_:()=>d,ts:()=>f});var a=r(41482),n=r.n(a),s=r(42023),o=r.n(s),i=r(71615),u=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function d(e){return o().hash(e,12)}async function l(e,t){return o().compare(e,t)}function m(e){return n().sign(e,c,{expiresIn:"7d"})}function p(e){try{return n().verify(e,c)}catch{return null}}async function f(){let e=await (0,i.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=p(t);return r?await u._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function g(e,t){return t.includes(e)}function x(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>n});let a=require("@prisma/client"),n=globalThis.prisma??new a.PrismaClient},45239:(e,t,r)=>{r.d(t,{F:()=>s});var a=r(87070),n=r(15230);async function s(e,t){let r=await (0,n.p6)(e);return(0,n.U6)(r.features,t)?null:a.NextResponse.json({error:"Fitur ini tidak tersedia pada paket Anda. Silakan upgrade."},{status:403})}},15230:(e,t,r)=>{r.d(t,{MN:()=>s,U6:()=>o,p6:()=>n});var a=r(8194);async function n(e){let t=await a._.subscription.findFirst({where:{tenantId:e,status:{in:["active","trial"]}},include:{plan:!0},orderBy:{createdAt:"desc"}});return t?{maxStores:t.plan.maxStores,maxStaff:t.plan.maxStaff,maxMenuItems:t.plan.maxMenuItems,maxOrders:t.plan.maxOrders,features:JSON.parse(t.plan.features)}:{maxStores:1,maxStaff:3,maxMenuItems:30,maxOrders:100,features:["pos","qr_menu"]}}async function s(e,t){let r=await n(e),s=0,o=0;switch(t){case"stores":s=await a._.store.count({where:{tenantId:e,isActive:!0}}),o=r.maxStores;break;case"staff":s=await a._.user.count({where:{tenantId:e,isActive:!0}}),o=r.maxStaff;break;case"menuItems":s=await a._.menuItem.count({where:{tenantId:e,isActive:!0}}),o=r.maxMenuItems;break;case"orders":let i=new Date;i.setDate(1),i.setHours(0,0,0,0),s=await a._.order.count({where:{tenantId:e,createdAt:{gte:i}}}),o=r.maxOrders}return 0===o?{allowed:!0,current:s,max:o}:{allowed:s<o,current:s,max:o}}function o(e,t){return e.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,2023],()=>r(37964));module.exports=a})();