"use strict";(()=>{var e={};e.id=414,e.ids=[414],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")},27513:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>_,requestAsyncStorage:()=>m,routeModule:()=>c,serverHooks:()=>w,staticGenerationAsyncStorage:()=>f});var n={};r.r(n),r.d(n,{POST:()=>d});var a=r(49303),s=r(88716),i=r(60670),o=r(87070),u=r(8194),l=r(95456),p=r(56811);async function d(e){try{let t=await (0,l.ts)();if(!t)return o.NextResponse.json({error:"Unauthorized"},{status:401});if("owner"!==t.role&&"admin"!==t.role)return o.NextResponse.json({error:"Hanya owner/admin yang bisa menarik dana"},{status:403});let{amount:r,bankName:n,bankAccount:a,bankHolder:s,notes:i}=await e.json();if(!r||!n||!a||!s)return o.NextResponse.json({error:"Data penarikan tidak lengkap"},{status:400});let d=await (0,p.$X)(),c=parseInt(d.min_withdrawal)||5e4;if(r<c)return o.NextResponse.json({error:`Minimum penarikan ${c.toLocaleString("id-ID")}`},{status:400});let m=await u._.tenantWallet.findUnique({where:{tenantId:t.tenantId}});if(!m||Number(m.balance)<r)return o.NextResponse.json({error:"Saldo tidak mencukupi"},{status:400});if(await u._.withdrawalRequest.findFirst({where:{tenantId:t.tenantId,status:"pending"}}))return o.NextResponse.json({error:"Masih ada penarikan yang menunggu persetujuan"},{status:400});let f=await u._.withdrawalRequest.create({data:{tenantId:t.tenantId,walletId:m.id,amount:r,bankName:n,bankAccount:a,bankHolder:s,notes:i||null,status:"pending"}});return o.NextResponse.json({withdrawal:f},{status:201})}catch{return o.NextResponse.json({error:"Server error"},{status:500})}}let c=new a.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/wallet/withdraw/route",pathname:"/api/wallet/withdraw",filename:"route",bundlePath:"app/api/wallet/withdraw/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\wallet\\withdraw\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:m,staticGenerationAsyncStorage:f,serverHooks:w}=c,h="/api/wallet/withdraw/route";function _(){return(0,i.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:f})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>d,MH:()=>w,PT:()=>h,RA:()=>c,WX:()=>m,c_:()=>p,ts:()=>f});var n=r(41482),a=r.n(n),s=r(42023),i=r.n(s),o=r(71615),u=r(8194);let l=process.env.JWT_SECRET||"fallback-secret-change-me";async function p(e){return i().hash(e,12)}async function d(e,t){return i().compare(e,t)}function c(e){return a().sign(e,l,{expiresIn:"7d"})}function m(e){try{return a().verify(e,l)}catch{return null}}async function f(){let e=await (0,o.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 w(e,t){return t.includes(e)}function h(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>a});let n=require("@prisma/client"),a=globalThis.prisma??new n.PrismaClient},56811:(e,t,r)=>{r.d(t,{$X:()=>i,Km:()=>s,Rx:()=>o,ks:()=>u});var n=r(8194);let a={payment_fee_mode:"percentage",payment_fee_amount:"2.5",payment_enabled:"true",min_withdrawal:"50000",affiliate_commission_rate:"10",affiliate_enabled:"true",affiliate_min_withdrawal:"50000",email_verification_enabled:"false",smtp_host:"",smtp_port:"587",smtp_user:"",smtp_pass:"",smtp_from_email:"",smtp_from_name:"RestoMenu",smtp_secure:"false"};async function s(e){let t=await n._.platformSetting.findUnique({where:{key:e}});return t?.value??a[e]??""}async function i(){let e=await n._.platformSetting.findMany(),t={...a};for(let r of e)t[r.key]=r.value;return t}async function o(e){let t=Object.entries(e).map(([e,t])=>n._.platformSetting.upsert({where:{key:e},update:{value:t},create:{key:e,value:t}}));await n._.$transaction(t)}function u(e,t,r){let n=parseFloat(r)||0,a=0;a=Math.min(a="percentage"===t?Math.round(e*n/100):Math.round(n),e);let s=e-a;return{fee:a,tenantAmount:s}}}};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(27513));module.exports=n})();