import{r as n,j as e}from"./login-aN2dRsX6.js";import{n as N,o as k}from"./query-c3dDncii.js";import{b as g,a as w}from"./alert-CsXKWu2a.js";import{u as v}from"./modalAkun-DKxSDKLU.js";import{M as d}from"./Modal-Dn58D0E5.js";import{S as y}from"./search-4uBqei5W.js";const D=({onSelected:l})=>{const[h,x]=n.useState(!1),[m,b]=n.useState(),[c,j]=n.useState(""),u=N(),i=v({onSubmit:async s=>{const t=await k(s),a=await t.json();return t.status==200||t.status==201?(u.refetch(),await g("Akun berhasil disimpan"),!0):(await w(a.message),!1)}}),f=s=>{x(!0),b(s)},o=()=>{x(!1)},p=n.useCallback(()=>{const s=u.data??[];if(c.trim()!==""){let t=s;return t=s.filter(a=>{var r;return(r=a.kode_akun)==null?void 0:r.toString().toLowerCase().includes(c.toLowerCase())}),t.length===0&&(t=s.filter(a=>{var r;return(r=a.nama)==null?void 0:r.toLowerCase().includes(c.toLowerCase())})),t}return s},[u,c]);return{modal:n.useMemo(()=>e.jsxs(e.Fragment,{children:[e.jsxs(d,{show:h,onHide:o,size:"lg",scrollable:!0,className:"modal-browse-akun",onExited:()=>j(""),children:[e.jsx(d.Header,{closeButton:!0,children:e.jsx("h5",{className:"m-0",children:"Daftar Akun"})}),e.jsx(d.Body,{className:"p-0",children:e.jsxs("table",{className:"table-bordered mb-0 table-sm table-hover table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"fixed",children:[e.jsx("th",{className:"text-center",children:"Kode Akun"}),e.jsx("th",{children:"Nama Akun"}),e.jsx("th",{className:"text-center",children:"Kategori"}),e.jsx("th",{className:"text-center",children:"Jurnal"}),e.jsx("th",{className:"text-center",children:"Aksi"})]})}),e.jsx("tbody",{children:p().map(s=>e.jsxs("tr",{children:[e.jsx("td",{className:"text-center",width:100,children:s.kode_akun}),e.jsx("td",{children:s.nama}),e.jsx("td",{className:"text-center",width:120,children:s.kategori}),e.jsx("td",{className:"text-center",width:100,children:s.jurnal}),e.jsx("td",{width:100,className:"text-center",children:e.jsxs("div",{className:"d-flex justify-content-center gap-2",children:[e.jsx("div",{className:"badge text-bg-primary",style:{cursor:"pointer"},onClick:()=>{o(),l==null||l({akun:s,selector:m})},children:"Pilih"}),e.jsx("div",{className:"badge text-bg-warning",style:{cursor:"pointer"},onClick:()=>{i.open(s)},children:"Edit"})]})})]},s.id))})]})}),e.jsxs(d.Footer,{className:"justify-content-between",children:[e.jsx("div",{className:"row",children:e.jsxs("div",{className:"d-flex gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"input-group",children:[e.jsx("input",{className:"form-control border-end-0",onChange:s=>j(s.target.value)}),e.jsx("span",{className:"input-group-text bg-white",children:e.jsx(y,{size:18})})]})}),e.jsx("div",{children:e.jsx("button",{className:"btn btn-primary",onClick:()=>i.open(),children:"Buat Akun Baru"})})]})}),e.jsx("div",{children:e.jsx("button",{className:"btn btn-primary",onClick:o,children:"Tutup"})})]})]}),i.modal]}),[p,i,l,h,m]),open:f,close:o}};export{D as u};
