(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,38043,e=>{"use strict";var a=e.i(43476),n=e.i(71645),t=e.i(18566),s=e.i(11795);function r({label:e,children:n}){return(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium mb-1",children:e}),n]})}e.s(["default",0,function({userId:e,initial:l}){let u=(0,t.useRouter)(),c=(0,s.createClient)(),[i,m]=(0,n.useState)(l?.type??"mpesa"),[b,d]=(0,n.useState)(l?.mpesa_msisdn??""),[o,p]=(0,n.useState)({bank_name:l?.bank_name??"",bank_account_name:l?.bank_account_name??"",bank_account_number:l?.bank_account_number??"",bank_branch:l?.bank_branch??""}),[_,x]=(0,n.useState)(null),[h,g]=(0,n.useState)(!1),[k,v]=(0,n.useState)(!1);async function f(a){let n;a.preventDefault(),v(!0),x(null),g(!1);let t="mpesa"===i?{organizer_id:e,type:i,mpesa_msisdn:(n=b.replace(/\D/g,"")).startsWith("254")?n:n.startsWith("0")?`254${n.slice(1)}`:n.startsWith("7")||n.startsWith("1")?`254${n}`:n,bank_name:null,bank_account_name:null,bank_account_number:null,bank_branch:null}:{organizer_id:e,type:i,mpesa_msisdn:null,bank_name:o.bank_name,bank_account_name:o.bank_account_name,bank_account_number:o.bank_account_number,bank_branch:o.bank_branch},{error:s}=await c.from("payout_accounts").upsert(t,{onConflict:"organizer_id"});if(s){x(s.message),v(!1);return}g(!0),v(!1),u.refresh()}return(0,a.jsxs)("form",{onSubmit:f,className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"flex rounded-md border border-be-border p-1 text-sm",children:["mpesa","bank"].map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>m(e),className:`rounded px-3 py-1.5 font-medium capitalize transition-colors ${i===e?"bg-brand-green text-white":"text-be-muted hover:text-be-text"}`,children:"mpesa"===e?"M-Pesa":"Bank"},e))}),l?.verified?(0,a.jsx)("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Verified"}):l?(0,a.jsx)("span",{className:"rounded-full bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-700",children:"Pending verification"}):null]}),"mpesa"===i?(0,a.jsx)(r,{label:"M-Pesa number",children:(0,a.jsx)("input",{required:!0,type:"tel",placeholder:"07XX XXX XXX",value:b,onChange:e=>d(e.target.value),className:"input"})}):(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(r,{label:"Bank name",children:(0,a.jsx)("input",{required:!0,value:o.bank_name,onChange:e=>p({...o,bank_name:e.target.value}),className:"input"})}),(0,a.jsx)(r,{label:"Account name",children:(0,a.jsx)("input",{required:!0,value:o.bank_account_name,onChange:e=>p({...o,bank_account_name:e.target.value}),className:"input"})}),(0,a.jsx)(r,{label:"Account number",children:(0,a.jsx)("input",{required:!0,value:o.bank_account_number,onChange:e=>p({...o,bank_account_number:e.target.value}),className:"input"})}),(0,a.jsx)(r,{label:"Branch",children:(0,a.jsx)("input",{value:o.bank_branch,onChange:e=>p({...o,bank_branch:e.target.value}),className:"input"})})]}),_&&(0,a.jsx)("p",{className:"text-sm text-red-600",children:_}),h&&(0,a.jsx)("p",{className:"text-sm text-green-600",children:"Payout details saved."}),(0,a.jsx)("button",{type:"submit",disabled:k,className:"rounded-md bg-brand-green px-4 py-2 text-sm font-medium text-white hover:bg-brand-green-deep disabled:opacity-50",children:k?"Saving…":"Save payout details"})]})}])}]);