import{u as v,R as i,m as S,j as t}from"./app-DBtZ8h0a.js";import{b as g}from"./index-6FD8lOav.js";import{v as C,P as _,f as D}from"./payment-utils-b3cBI-QJ.js";const F=({selectedMethod:f,siswa:e,totalAmount:s=0,existingTransaction:d,onSubmit:o,processing:r=!1,errors:u={}})=>{const{log:n}=v(),[l,x]=i.useState({method:"wallet",exist:(d==null?void 0:d.exist)||!1}),{data:b,setData:h}=S({payment_method:l.method,uri:(d==null?void 0:d.uri)||""});i.useEffect(()=>{h("payment_method",l.method)},[l.method,h]);const m=i.useMemo(()=>(e==null?void 0:e.balance)===void 0||(e==null?void 0:e.balance)===null?(n("No balance available, returning false"),!1):!C(e.balance,s||0).isValid,[e==null?void 0:e.balance,s,n]),c=i.useMemo(()=>r?(n("Submit disabled: processing"),!0):l.method==="wallet"&&m?(n("Submit disabled: wallet method with insufficient balance"),!0):l.method==="va"&&l.exist?(n("Submit enabled: VA method with existing transaction"),!1):(n("Submit enabled: default case"),!1),[r,l.method,m,l.exist,n]),j=a=>{x(y=>({...y,method:a})),f(a)},k=a=>{a.preventDefault(),!c&&o&&o(l.method)},p=()=>{b.uri&&(window.location.href=b.uri)},N=a=>l.method!==a?null:a==="wallet"?t.jsxs("div",{className:"mt-1 text-sm text-gray-500",children:[t.jsxs("p",{children:["Saldo Tersedia : ",D((e==null?void 0:e.balance)??0)]}),m?t.jsx("p",{className:"text-red-500",children:"Saldo tidak mencukupi untuk melakukan transaksi ini"}):t.jsx("p",{children:"Cukup dan aman untuk bertransaksi"})]}):a==="va"?l.exist?t.jsxs("div",{className:"mt-4 rounded-lg border-l-4 border-yellow-500 bg-yellow-100 p-4 text-yellow-700 shadow-sm",children:[t.jsx("p",{className:"font-semibold",children:"Transaksi Belum Selesai"}),t.jsx("p",{className:"mt-1",children:"Anda memiliki transaksi yang belum selesai. Silakan selesaikan transaksi sebelumnya untuk melanjutkan."})]}):t.jsx("div",{className:"mt-1 text-sm text-gray-500",children:"Transfer melalui bank partner"}):null;return i.useEffect(()=>{(l.method||n||e!=null&&e.balance||s)&&n("Checking saldo insufficiency:",{method:l.method,balance:e==null?void 0:e.balance,totalAmount:s,isWallet:l.method==="wallet",hasBalance:!!(e!=null&&e.balance)}),(m||r||l.exist)&&n("Checking isSubmitDisabled:",{processing:r,method:l.method,isSaldoInsufficient:m,exist:l.exist})},[l.method,n,e==null?void 0:e.balance,s,m,r,l.exist]),t.jsxs("div",{className:"p-4",children:[t.jsx("h2",{className:"mb-3 text-md font-semibold",children:"Metode Pembayaran"}),t.jsxs("form",{onSubmit:k,children:[t.jsx("div",{className:"space-y-4",children:_.filter(a=>!a.disabled).map(a=>t.jsxs("div",{className:"flex items-start",children:[t.jsx("div",{className:"flex h-5 items-center",children:t.jsx("input",{id:a.id,name:"payment_method",type:"radio",checked:l.method===a.type,onChange:()=>j(a.type),className:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500",disabled:r})}),t.jsxs("div",{className:"ml-3 flex-1",children:[t.jsxs("label",{htmlFor:a.id,className:"flex items-center text-sm font-medium text-gray-700 sm:text-base",children:[a.icon&&t.jsx("span",{className:"mr-2 flex items-center",children:i.createElement(a.icon,{size:16})}),a.label]}),N(a.type)]})]},a.id))}),u.payment_method&&t.jsx("p",{className:"mt-2 text-sm text-red-600",children:u.payment_method}),t.jsx("div",{className:"mt-6 flex justify-end sm:mt-8",children:l.method==="va"&&l.exist?t.jsx("button",{type:"button",onClick:p,className:"mt-3 inline-block rounded bg-yellow-600 px-4 py-2 font-medium text-white transition hover:bg-yellow-700",children:"Lanjutkan ke Transaksi"}):t.jsx("button",{type:"submit",disabled:c,className:`rounded-md px-6 py-3 text-base font-medium text-white shadow-sm transition-colors ${c?"cursor-not-allowed bg-gray-400":"bg-blue-600 hover:bg-blue-700 focus:ring-2 focus:ring-blue-500 focus:outline-none"}`,children:r?t.jsxs("span",{className:"flex items-center justify-center",children:[t.jsx(g,{className:"mr-2 animate-spin"}),"Memproses..."]}):"Bayar Sekarang"})})]})]})};export{F as P};
