"use strict";(()=>{var e={};e.id=6545,e.ids=[6545],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")},96510:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>g,requestAsyncStorage:()=>x,routeModule:()=>m,serverHooks:()=>y,staticGenerationAsyncStorage:()=>f});var n={};r.r(n),r.d(n,{DELETE:()=>p,PUT:()=>l});var s=r(49303),a=r(88716),o=r(60670),i=r(87070),u=r(8194),d=r(95456),c=r(57662);async function l(e,{params:t}){try{let r=await (0,d.ts)();if(!r)return i.NextResponse.json({error:"Unauthorized"},{status:401});if(!["owner","admin"].includes(r.role))return i.NextResponse.json({error:"Forbidden"},{status:403});let{id:n}=await t,s=await e.json(),a=await u._.store.update({where:{id:n,tenantId:r.tenantId},data:s});return(0,c.w)({tenantId:r.tenantId,userId:r.id,userName:r.name,userRole:r.role,action:"UPDATE",entity:"Store",entityId:n,description:`Mengubah cabang "${a.name}"`,meta:{changes:s}}),i.NextResponse.json({store:a})}catch{return i.NextResponse.json({error:"Server error"},{status:500})}}async function p(e,{params:t}){try{let e=await (0,d.ts)();if(!e)return i.NextResponse.json({error:"Unauthorized"},{status:401});if("owner"!==e.role)return i.NextResponse.json({error:"Forbidden"},{status:403});let{id:r}=await t,n=await u._.store.findFirst({where:{id:r,tenantId:e.tenantId},select:{name:!0}});return await u._.store.delete({where:{id:r,tenantId:e.tenantId}}),(0,c.w)({tenantId:e.tenantId,userId:e.id,userName:e.name,userRole:e.role,action:"DELETE",entity:"Store",entityId:r,description:`Menghapus cabang "${n?.name||r}"`}),i.NextResponse.json({success:!0})}catch{return i.NextResponse.json({error:"Server error"},{status:500})}}let m=new s.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/stores/[id]/route",pathname:"/api/stores/[id]",filename:"route",bundlePath:"app/api/stores/[id]/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\stores\\[id]\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:x,staticGenerationAsyncStorage:f,serverHooks:y}=m,h="/api/stores/[id]/route";function g(){return(0,o.patchFetch)({serverHooks:y,staticGenerationAsyncStorage:f})}},57662:(e,t,r)=>{r.d(t,{w:()=>a});var n=r(8194);async function s(e){return n._.auditLog.create({data:{tenantId:e.tenantId,userId:e.userId||null,userName:e.userName||null,userRole:e.userRole||null,action:e.action,entity:e.entity,entityId:e.entityId||null,description:e.description,meta:e.meta?JSON.stringify(e.meta):null}})}function a(e){s(e).catch(e=>{console.error("[AuditLog] Failed to log activity:",e)})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>l,MH:()=>f,PT:()=>y,RA:()=>p,WX:()=>m,c_:()=>c,ts:()=>x});var n=r(41482),s=r.n(n),a=r(42023),o=r.n(a),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 s().sign(e,d,{expiresIn:"7d"})}function m(e){try{return s().verify(e,d)}catch{return null}}async function x(){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 f(e,t){return t.includes(e)}function y(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(96510));module.exports=n})();