"use strict";(()=>{var e={};e.id=921,e.ids=[921],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")},7243:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>y,requestAsyncStorage:()=>m,routeModule:()=>f,serverHooks:()=>w,staticGenerationAsyncStorage:()=>x});var n={};r.r(n),r.d(n,{DELETE:()=>p,PUT:()=>l});var s=r(49303),a=r(88716),i=r(60670),o=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 o.NextResponse.json({error:"Unauthorized"},{status:401});if(!["owner","admin"].includes(r.role))return o.NextResponse.json({error:"Forbidden"},{status:403});let{id:n}=await t,s=await e.json();s.password?s.password=await (0,d.c_)(s.password):delete s.password;let a=await u._.user.update({where:{id:n,tenantId:r.tenantId},data:s,select:{id:!0,name:!0,email:!0,role:!0,phone:!0,isActive:!0,storeId:!0,createdAt:!0,store:{select:{id:!0,name:!0}}}});return(0,c.w)({tenantId:r.tenantId,userId:r.id,userName:r.name,userRole:r.role,action:"UPDATE",entity:"Staff",entityId:n,description:`Mengubah staff "${a.name}"`,meta:{changes:{...s,password:s.password?"***":void 0}}}),o.NextResponse.json({staff:a})}catch{return o.NextResponse.json({error:"Server error"},{status:500})}}async function p(e,{params:t}){try{let e=await (0,d.ts)();if(!e)return o.NextResponse.json({error:"Unauthorized"},{status:401});if("owner"!==e.role)return o.NextResponse.json({error:"Forbidden"},{status:403});let{id:r}=await t;if(r===e.id)return o.NextResponse.json({error:"Tidak bisa menghapus akun sendiri"},{status:400});let n=await u._.user.findFirst({where:{id:r,tenantId:e.tenantId},select:{name:!0,email:!0}});return await u._.user.update({where:{id:r,tenantId:e.tenantId},data:{isActive:!1}}),(0,c.w)({tenantId:e.tenantId,userId:e.id,userName:e.name,userRole:e.role,action:"DELETE",entity:"Staff",entityId:r,description:`Menonaktifkan staff "${n?.name||r}"`,meta:{name:n?.name,email:n?.email}}),o.NextResponse.json({success:!0})}catch{return o.NextResponse.json({error:"Server error"},{status:500})}}let f=new s.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/staff/[id]/route",pathname:"/api/staff/[id]",filename:"route",bundlePath:"app/api/staff/[id]/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\staff\\[id]\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:m,staticGenerationAsyncStorage:x,serverHooks:w}=f,h="/api/staff/[id]/route";function y(){return(0,i.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:x})}},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:()=>x,PT:()=>w,RA:()=>p,WX:()=>f,c_:()=>c,ts:()=>m});var n=r(41482),s=r.n(n),a=r(42023),i=r.n(a),o=r(71615),u=r(8194);let d=process.env.JWT_SECRET||"fallback-secret-change-me";async function c(e){return i().hash(e,12)}async function l(e,t){return i().compare(e,t)}function p(e){return s().sign(e,d,{expiresIn:"7d"})}function f(e){try{return s().verify(e,d)}catch{return null}}async function m(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=f(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 w(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(7243));module.exports=n})();