"use strict";(()=>{var e={};e.id=9234,e.ids=[9234],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")},10781:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>x,patchFetch:()=>f,requestAsyncStorage:()=>m,routeModule:()=>l,serverHooks:()=>w,staticGenerationAsyncStorage:()=>v});var n={};t.r(n),t.d(n,{DELETE:()=>c,PUT:()=>p});var a=t(49303),i=t(88716),s=t(60670),u=t(87070),o=t(8194),d=t(95456);async function p(e,{params:r}){try{let t=await (0,d.ts)();if(!t)return u.NextResponse.json({error:"Unauthorized"},{status:401});if(!["owner","admin","manager"].includes(t.role))return u.NextResponse.json({error:"Forbidden"},{status:403});let{id:n,groupId:a}=await r,i=await e.json();if(!await o._.menuVariantGroup.findFirst({where:{id:a,menuItemId:n,menuItem:{tenantId:t.tenantId}}}))return u.NextResponse.json({error:"Grup varian tidak ditemukan"},{status:404});if(await o._.menuVariantGroup.update({where:{id:a},data:{name:i.name,required:i.required,maxSelect:i.maxSelect}}),i.variants){let e=await o._.menuVariant.findMany({where:{variantGroupId:a},select:{id:!0}});e.length>0&&await o._.orderItemVariant.updateMany({where:{menuVariantId:{in:e.map(e=>e.id)}},data:{menuVariantId:null}}),await o._.menuVariant.deleteMany({where:{variantGroupId:a}}),await o._.menuVariant.createMany({data:i.variants.map((e,r)=>({variantGroupId:a,name:e.name,priceAdjustment:e.priceAdjustment||0,isAvailable:!1!==e.isAvailable,sortOrder:r}))})}let s=await o._.menuVariantGroup.findUnique({where:{id:a},include:{variants:{orderBy:{sortOrder:"asc"}}}});return u.NextResponse.json({variantGroup:s})}catch(e){return console.error("PUT variant group error:",e),u.NextResponse.json({error:"Server error"},{status:500})}}async function c(e,{params:r}){try{let e=await (0,d.ts)();if(!e)return u.NextResponse.json({error:"Unauthorized"},{status:401});if(!["owner","admin","manager"].includes(e.role))return u.NextResponse.json({error:"Forbidden"},{status:403});let{id:t,groupId:n}=await r;if(!await o._.menuVariantGroup.findFirst({where:{id:n,menuItemId:t,menuItem:{tenantId:e.tenantId}}}))return u.NextResponse.json({error:"Grup varian tidak ditemukan"},{status:404});let a=await o._.menuVariant.findMany({where:{variantGroupId:n},select:{id:!0}});return a.length>0&&await o._.orderItemVariant.updateMany({where:{menuVariantId:{in:a.map(e=>e.id)}},data:{menuVariantId:null}}),await o._.menuVariantGroup.delete({where:{id:n}}),u.NextResponse.json({success:!0})}catch(e){return console.error("DELETE variant group error:",e),u.NextResponse.json({error:"Server error"},{status:500})}}let l=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/menu/[id]/variants/[groupId]/route",pathname:"/api/menu/[id]/variants/[groupId]",filename:"route",bundlePath:"app/api/menu/[id]/variants/[groupId]/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\menu\\[id]\\variants\\[groupId]\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:m,staticGenerationAsyncStorage:v,serverHooks:w}=l,x="/api/menu/[id]/variants/[groupId]/route";function f(){return(0,s.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:v})}},95456:(e,r,t)=>{t.d(r,{Gv:()=>c,MH:()=>w,PT:()=>x,RA:()=>l,WX:()=>m,c_:()=>p,ts:()=>v});var n=t(41482),a=t.n(n),i=t(42023),s=t.n(i),u=t(71615),o=t(8194);let d=process.env.JWT_SECRET||"fallback-secret-change-me";async function p(e){return s().hash(e,12)}async function c(e,r){return s().compare(e,r)}function l(e){return a().sign(e,d,{expiresIn:"7d"})}function m(e){try{return a().verify(e,d)}catch{return null}}async function v(){let e=await (0,u.cookies)(),r=e.get("token")?.value;if(!r)return null;let t=m(r);return t?await o._.user.findUnique({where:{id:t.userId},include:{tenant:!0,store:!0}}):null}function w(e,r){return r.includes(e)}function x(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,r,t)=>{t.d(r,{_:()=>a});let n=require("@prisma/client"),a=globalThis.prisma??new n.PrismaClient}};var r=require("../../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),n=r.X(0,[8948,5972,4261,2023],()=>t(10781));module.exports=n})();