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

//# sourceMappingURL=src_app_dashboard_earnings_payout-account-form_tsx_132gdmo._.js.map