"use strict";(()=>{var e={};e.id=7163,e.ids=[7163],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")},2057:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>m,requestAsyncStorage:()=>l,routeModule:()=>p,serverHooks:()=>x,staticGenerationAsyncStorage:()=>g});var n={};r.r(n),r.d(n,{PATCH:()=>d});var s=r(49303),i=r(88716),a=r(60670),o=r(87070),u=r(8194),c=r(95456);async function d(e,{params:t}){try{let e=await (0,c.ts)();if(!e)return o.NextResponse.json({error:"Unauthorized"},{status:401});if(!["owner","admin"].includes(e.role))return o.NextResponse.json({error:"Forbidden"},{status:403});let{id:r}=await t,n=await u._.store.findFirst({where:{id:r,tenantId:e.tenantId},include:{_count:{select:{orders:{where:{status:{in:["pending","confirmed","preparing","ready"]}}}}}}});if(!n)return o.NextResponse.json({error:"Cabang tidak ditemukan"},{status:404});let s=!n.isActive,i=0;s||(i=n._count.orders);let a=await u._.store.update({where:{id:r,tenantId:e.tenantId},data:{isActive:s}});return o.NextResponse.json({store:a,activeOrdersCount:i,message:s?"Cabang diaktifkan":"Cabang dinonaktifkan"})}catch{return o.NextResponse.json({error:"Server error"},{status:500})}}let p=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/stores/[id]/toggle/route",pathname:"/api/stores/[id]/toggle",filename:"route",bundlePath:"app/api/stores/[id]/toggle/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\stores\\[id]\\toggle\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:l,staticGenerationAsyncStorage:g,serverHooks:x}=p,f="/api/stores/[id]/toggle/route";function m(){return(0,a.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:g})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>p,MH:()=>f,PT:()=>m,RA:()=>l,WX:()=>g,c_:()=>d,ts:()=>x});var n=r(41482),s=r.n(n),i=r(42023),a=r.n(i),o=r(71615),u=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function d(e){return a().hash(e,12)}async function p(e,t){return a().compare(e,t)}function l(e){return s().sign(e,c,{expiresIn:"7d"})}function g(e){try{return s().verify(e,c)}catch{return null}}async function x(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=g(t);return r?await u._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function f(e,t){return t.includes(e)}function m(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>s});let n=require("@prisma/client"),s=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(2057));module.exports=n})();