import{j as t,f as v,q as D}from"./app-Bup04Qnx.js";import{F as _,a as b}from"./FormBuilder-B6qVpe84.js";import{u as y}from"./format-CisCU4Rs.js";import{u as N}from"./useFormBuilder-w_BHcgkC.js";import{a as P}from"./Select-Cs0aMrtU.js";import{B as C}from"./BaseForm-wkPKZ5Eg.js";import"./Input-Bs1ncZB7.js";import"./TextArea-DiAj0IR8.js";import"./clsx-B-dksMZM.js";import"./floating-ui.dom-CwWDmSD9.js";import"./index-CtjruoRR.js";import"./index-Dy_g3AZ5.js";import"./useFormChange-D35moWjQ.js";function h({isEdit:s=!1}){const n=N({isEdit:s,getProperties:g});return t.jsx(_,{...n})}const g=s=>{var r,a;const{data:c,setData:n,props:l,isEdit:u}=s,{params:o}=y(l.location),d=l.status.map(e=>({label:P(e),value:e})),p=(e,i,x)=>{let m={};m[i]=(e==null?void 0:e.value)??"",m[i]||(m[i]=e??""),m.members=null,n(j=>({...j,...m})),o.set(i,m[i]),v.visit(`?${o.toString()}`,{method:"get",only:[...x,"location"],preserveState:!0,async:!1})};return[[{form:"input",props:{name:"name",label:"Nama Departemen",type:"text"}},{form:"input",isHidden:!u,props:{name:"code",label:"Kode Departemen",type:"text"}},{form:"select",isHidden:!["president_director"].includes((a=(r=l==null?void 0:l.auth)==null?void 0:r.user)==null?void 0:a.role),props:{isReactSelect:!0,isVirtualized:!0,name:"user_id",label:"Pilih Direktur",options:l.directors,handleChange:e=>p(e,"user_id",["members","managers","selected_user"])}},{form:"select",props:{isReactSelect:!0,isVirtualized:!0,name:"status",label:"Status",options:d,handleChange:e=>n("status",e==null?void 0:e.value)}}],[{form:"checkbox",props:{name:"is_finance",label:"Departemen Keuangan"}}],[{custom:e=>t.jsx(S,{...e,...s})}]]},S=s=>{const{members:c,managers:n}=D().props,{data:l,setData:u}=s.form,o=Array.isArray(l.details)?l.details:[],d=(r,a,e)=>{const i=[...o];i[r]={...i[r],[a]:e},u("details",i)},p=()=>{u("details",[...o,{manager_id:"",user_id:[]}])},f=r=>{const a=o.filter((e,i)=>i!==r);u("details",a)};return t.jsxs(C,{isLabel:!1,name:"details",errors:s==null?void 0:s.form.errors,children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsx("h3",{className:"text-lg font-semibold",children:"Detail Departemen"}),t.jsxs("button",{type:"button",className:"btn btn-primary btn-xs px-x rounded-sm",onClick:p,children:[t.jsx("i",{className:"fas fa-plus"})," Tambah Detail"]})]}),t.jsx("div",{className:"flex flex-col gap-6",children:o.map((r,a)=>t.jsxs("div",{className:"border p-4 rounded-lg bg-white relative",children:[t.jsx("button",{type:"button",className:"absolute top-2 right-2 text-red-500 hover:text-red-700 p-1",onClick:()=>f(a),title:"Hapus Detail",children:t.jsx("i",{className:"fas fa-trash"})}),t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-2",children:[t.jsx(b,{property:{form:"select",props:{isReactSelect:!0,isVirtualized:!0,isCreateAble:!0,name:"manager_id",label:"Manager",value:r.manager_id,options:n}},inputProps:{...s.inputProps,handleChange:e=>d(a,"manager_id",e==null?void 0:e.value),data:r}}),t.jsx("div",{className:"md:w-full md:col-span-3",children:t.jsx(b,{property:{form:"select",props:{isReactSelect:!0,isVirtualized:!0,isCreateAble:!0,isMulti:!0,name:"user_id",label:"Anggota",value:r.user_id,defaultValue:r.user_id,options:c}},inputProps:{...s.inputProps,handleChange:e=>d(a,"user_id",e),data:r}})})]})]},a))}),o.length===0&&t.jsx("p",{className:"text-center text-gray-400 py-4",children:'Belum ada detail departemen. Klik "Tambah Detail" untuk memulai.'})]})},F=({children:s})=>s(g);h.PropertiesProvider=F;const q=h;export{q as default};
