import{d as f,pu as y,r as k,j as e,I as D,aK as L,B as A,T as v,R as m,pv as w,og as C,pw as F,px as S}from"./index-e6164346.js";import{c as T,b as d,u as I}from"./index.esm-0a041314.js";import{o as B}from"./yup-5fd5d57b.js";import"./GenericThumbnailView-80c6fd98.js";import{F as E}from"./FormInput-859198ec.js";import"./componentStyles-00385170.js";import{L as M}from"./ScrollableList-5a17e8f4.js";import{T as R}from"./TextArea-f5c200de.js";import{D as z}from"./Dialog-2e8a8e2e.js";import{D as P}from"./DialogTitle-8757f50f.js";import{D as $}from"./DialogContent-f10d6731.js";import{D as q}from"./DialogContentText-027be15d.js";import{G as l}from"./Grid2-c9c87842.js";import{D as G}from"./DialogActions-31bec80e.js";const ie=()=>{const t=f(),{departments:{selectedData:r,loading:x,isModelVisible:h,pageParams:c},mini:{miniLocationList:U,miniLocationLoading:V,miniLocationParams:K},system:{userAccessList:N}}=y(),s=()=>{t(w({})),b(),t(C(!1))},i=r==null?void 0:r.id,u=T().shape({name:d().required("Please enter your department name").trim(),remarks:d().trim().matches(/^[a-zA-Z0-9 ]*$/,"remarks should not contain special characters")});k.useEffect(()=>{s()},[]);const{control:p,handleSubmit:j,reset:b}=I({resolver:B(u),values:{name:r!=null&&r.name?r==null?void 0:r.name:"",remarks:r!=null&&r.remarks?r==null?void 0:r.remarks:""}}),g=a=>{if(i){const n={obj:{id:i,name:a.name,remarks:a.remarks},pageParams:c,clearDataFn:()=>{s()}};t(S(n))}else{const n={obj:{name:a.name,remarks:a.remarks},pageParams:c,clearDataFn:()=>{s()}};t(F(n))}};return e.jsx(e.Fragment,{children:e.jsxs(z,{open:h,onClose:(a,o)=>{o!=="backdropClick"&&s()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(P,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[i?"Update ":"Add ","Department",e.jsx(D,{onClick:s,children:e.jsx(L,{color:"white"})})]}),e.jsx($,{sx:{px:"24px",pt:"12px !important",pb:0},children:x?e.jsxs(A,{children:[e.jsx(M,{}),e.jsx(v,{textAlign:"center",children:"Loading..."})]}):e.jsx(q,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:j(g),children:[e.jsxs(l,{container:!0,spacing:2,children:[e.jsx(l,{size:{xs:24},children:e.jsx(E,{required:!0,name:"name",label:"Name",type:"text",placeholder:"Enter Departments here...",control:p})}),e.jsx(l,{size:{xs:12},children:e.jsx(R,{name:"remarks",label:"Description",type:"text",placeholder:"Write description here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:p})})]}),e.jsxs(G,{sx:{p:2},children:[e.jsx(m,{onClick:s,variant:"outlined",color:"secondary",children:"Cancel"}),i?e.jsx(m,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"}):e.jsx(m,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"})]})]})})})]})})};export{ie as A};
