import{r,j as a}from"./app-DYGATBs5.js";import{M as N}from"./Modal-BgB_rn3w.js";import{b as k}from"./index-Bm2rgegR.js";/* empty css            */import"./utils-TqigrGrV.js";import"./InputGroup-DVO3HImr.js";import"./iconBase-DmVDVEai.js";import"./circle-alert-C2CB-9yq.js";import"./createLucideIcon-BtQHVCpb.js";import"./x-t5qumvGf.js";const S=["Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"],A=({open:c,onClose:d,nouid:n,setTambahTagihan:u})=>{const[h,f]=r.useState({}),[y,x]=r.useState(!1),[s,g]=r.useState(""),[l,m]=r.useState(""),[b,o]=r.useState(""),j=r.useCallback(async()=>{x(!0);try{const e=route("api.tagihan.exists",{nouid:n}),t=await fetch(e),i=await t.json();if(!t.ok)throw new Error(i.message);const p=i.data||{};f(p)}catch(e){console.error("Gagal ambil tagihan:",e)}finally{x(!1)}},[n]);r.useEffect(()=>{c&&(g(""),m(""),o(""),j())},[c,j]);const v=s?(h[s]||[]).sort((e,t)=>e-t).map(e=>({value:e,label:S[e-1]})):[],w=r.useCallback(async()=>{if(!s||!l){o("Harap pilih tahun dan bulan terlebih dahulu.");return}o("");try{const e=route("api.tagihan.add",{nouid:n})+`?t=${s}&b=${l}`,t=await fetch(e),i=await t.json();if(!t.ok||!i.success)throw new Error(i.message);const p=i.data||{};u(p),d(!1)}catch(e){console.error("Gagal ambil tagihan:",e),o("Gagal mengambil data tagihan. Coba lagi.")}},[n,s,l,d,u]);return a.jsx(N,{title:"Pilih Tagihan",isOpen:c,onClose:()=>d(!1),children:a.jsx("div",{className:"max-h-[75vh] space-y-6 overflow-y-auto px-1",children:y?a.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-gray-500",children:[a.jsx(k,{className:"mb-2 animate-spin text-2xl"}),a.jsx("span",{children:"Memuat data tagihan..."})]}):Object.keys(h).length===0?a.jsx("p",{className:"py-4 text-center text-gray-600",children:"Tidak ada data tagihan tersedia"}):a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-2",children:a.jsxs("div",{children:[a.jsx("label",{className:"mb-2 block text-sm font-semibold text-gray-700",children:"Sampai:"}),a.jsxs("div",{className:"flex flex-row gap-3",children:[a.jsxs("select",{value:s,onChange:e=>{g(e.target.value),m("")},className:"w-full rounded-md border bg-white px-4 py-2 text-gray-800",children:[a.jsx("option",{value:"",children:"-- Pilih Tahun --"}),Object.keys(h).sort((e,t)=>parseInt(t)-parseInt(e)).map(e=>a.jsxs("option",{value:e,children:["Tahun ",e]},e))]}),a.jsxs("select",{value:l,onChange:e=>m(parseInt(e.target.value)),className:"w-full rounded-md border bg-white px-4 py-2 text-gray-800 capitalize",disabled:!s,children:[a.jsx("option",{value:"",children:"-- Pilih Bulan --"}),v.map(({value:e,label:t})=>a.jsx("option",{value:e,children:t},e))]})]})]})}),b&&a.jsx("p",{className:"pt-2 text-sm text-red-600",children:b}),a.jsx("div",{className:"flex justify-end pt-4",children:a.jsx("button",{disabled:!s||!l,onClick:w,className:"rounded-md bg-blue-600 px-5 py-2 text-white transition hover:bg-blue-700",children:"Tambahkan Tagihan"})})]})})})};export{A as default};
