import{r as m,j as e}from"./login-aN2dRsX6.js";import{F as N,L as g,M as w}from"./query-c3dDncii.js";import{b as C,a as S}from"./alert-CsXKWu2a.js";import{B as j}from"./button_submit-wN0ayemz.js";import{D as E}from"./DataTable-D2rA17vR.js";import{P as y}from"./page_header-wdV8ucix.js";import{S as M}from"./SelectRole-Dys9Ftv0.js";import{M as d}from"./Modal-Dn58D0E5.js";import{S as k}from"./save-CB8xeERj.js";import{C as D}from"./circle-plus-D9wc3WnO.js";import{E as P}from"./eye-By1xm0Dd.js";import"./app-gmlkJjeD.js";import"./ThemeProvider-Cx_yflmw.js";import"./search-4uBqei5W.js";import"./createLucideIcon-C44k9nIN.js";import"./delete-PVCdpT-9.js";import"./Select-B6FG_hRH.js";import"./defineProperty-DRmM3rRU.js";import"./typeof-QjJsDpFa.js";import"./setPrototypeOf-B4fUID9J.js";import"./index-Ci65TyJp.js";import"./floating-ui.dom-C5vApqfE.js";const R=({onSubmit:o})=>{const[t,n]=m.useState(!1),[a,s]=m.useState(),i=N(),b=l=>{l&&s(l),n(!0)},c=()=>{n(!1)},f=()=>{s(void 0)},p=m.useCallback(l=>{s({...a,[l.target.name]:l.target.value.toString().toUpperCase()})},[a]);return{modal:m.useMemo(()=>{var l;return e.jsxs(d,{show:t,onHide:c,onExited:f,children:[e.jsx(d.Header,{closeButton:!0,children:e.jsx("h5",{className:"m-0",children:"Data User"})}),e.jsxs(d.Body,{children:[e.jsxs("div",{className:"row mb-2",children:[e.jsx("label",{className:"col-form-label col-md-4",children:"Username"}),e.jsx("div",{className:"col-md-8",children:e.jsx("input",{className:"form-control",name:"username",value:(a==null?void 0:a.username)||"",onChange:r=>{s({...a,username:r.target.value.toLowerCase()})}})})]}),e.jsxs("div",{className:"row mb-2",children:[e.jsx("label",{className:"col-form-label col-md-4",children:"Password"}),e.jsx("div",{className:"col-md-8",children:e.jsx("input",{className:"form-control",type:"password",name:"password",placeholder:"******",value:(a==null?void 0:a.password)||"",onChange:r=>{s({...a,password:r.target.value})}})})]}),e.jsxs("div",{className:"row mb-2",children:[e.jsx("label",{className:"col-form-label col-md-4",children:"Nama"}),e.jsx("div",{className:"col-md-8",children:e.jsx("input",{className:"form-control",name:"name",value:(a==null?void 0:a.name)||"",onChange:p})})]}),e.jsxs("div",{className:"row mb-2",children:[e.jsx("label",{className:"col-form-label col-md-4",children:"Email"}),e.jsx("div",{className:"col-md-8",children:e.jsx("input",{className:"form-control",name:"email",value:(a==null?void 0:a.email)||"",onChange:r=>{s({...a,email:r.target.value.toLowerCase()})}})})]}),e.jsx("hr",{}),e.jsxs("div",{className:"row mb-2",children:[e.jsx("label",{className:"col-form-label col-md-4",children:"Role"}),e.jsx("div",{className:"col-md-8",children:e.jsx(M,{value:(l=a==null?void 0:a.role_id)==null?void 0:l.toString(),onChange:r=>{var h;const u=(h=i.data)==null?void 0:h.find(v=>{var x;return((x=v.id)==null?void 0:x.toString())==r});u&&s({...a,role:u,role_id:u.id})}})})]})]}),e.jsxs(d.Footer,{children:[e.jsx("button",{className:"btn btn-primary",onClick:c,children:"Tutup"}),e.jsx(j,{className:"btn-success",icon:e.jsx(k,{size:18}),onClick:async()=>{o&&a&&await o(a)&&c()},children:"Simpan"})]})]})},[a,p,o,i.data,t]),open:b,close:c}};function ae(){const o=g(),t=R({onSubmit:async a=>{const s=await w(a),i=await s.json();return s.status==200||s.status==201?(o.refetch(),await C("User berhasil disimpan"),!0):(await S(i.message),!1)}}),n=[{label:"Nama",value:a=>a.name},{label:e.jsx("center",{children:"Username"}),width:200,align:"center",value:a=>a.username},{label:e.jsx("center",{children:"Email"}),width:200,align:"center",value:a=>a.email},{label:e.jsx("center",{children:"Role"}),width:200,align:"center",value:a=>{var s;return(s=a.role)==null?void 0:s.nama}},{label:e.jsx("center",{}),width:80,align:"center",value:a=>e.jsx("span",{onClick:()=>t.open(a),className:"c-pointer",children:e.jsx(P,{size:18})})}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container",children:[e.jsx(y,{title:"Data User",breadcrumb:[{title:"Pengaturan",path:"/app/pengaturan"},{title:"User",path:"/app/pengaturan/user"}]}),e.jsx(E,{data:o.data??[],column:n,search:!0,pagination:!0,item_per_page:15,buttons:e.jsx(j,{className:"btn btn-primary",onClick:t.open,icon:e.jsx(D,{size:18}),children:"Tambah User"})})]}),t.modal]})}export{ae as default};
