import{d as y,oA as f,r as k,j as e,I as D,aI as A,B as L,T as C,R as m,oB as F,nm as S,oC as v,oD as w}from"./index-ba11e6ab.js";import{c as I,b as d,u as T}from"./index.esm-39ef576a.js";import{o as B}from"./yup-902af9ab.js";import"./GenericThumbnailView-511a7e33.js";import{F as E}from"./FormInput-3e62ad24.js";import"./componentStyles-cc6f218d.js";import{L as M}from"./ScrollableList-b4fc4d99.js";import{T as R}from"./TextArea-1c46e0e4.js";import{D as z,a as P}from"./DialogContent-af77e042.js";import{D as $}from"./DialogTitle-dc43931f.js";import{D as q}from"./DialogContentText-990aa19e.js";import{G as l}from"./Grid2-12794a3c.js";import{D as G}from"./DialogActions-3fe54b4c.js";const oe=()=>{const o=y(),{departments:{selectedData:r,loading:x,isModelVisible:h,pageParams:c},mini:{miniLocationList:U,miniLocationLoading:V,miniLocationParams:N},system:{userAccessList:W}}=f(),a=()=>{o(F({})),b(),o(S(!1))},t=r==null?void 0:r.id,u=I().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(()=>{a()},[]);const{control:p,handleSubmit:j,reset:b}=T({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=s=>{if(t){const n={obj:{id:t,name:s.name,remarks:s.remarks},pageParams:c,clearDataFn:()=>{a()}};o(w(n))}else{const n={obj:{name:s.name,remarks:s.remarks},pageParams:c,clearDataFn:()=>{a()}};o(v(n))}};return e.jsx(e.Fragment,{children:e.jsxs(z,{open:h,onClose:(s,i)=>{i!=="backdropClick"&&a()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs($,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[t?"Update ":"Add ","Department",e.jsx(D,{onClick:a,children:e.jsx(A,{color:"white"})})]}),e.jsx(P,{sx:{px:"24px",pt:"12px !important",pb:0},children:x?e.jsxs(L,{children:[e.jsx(M,{}),e.jsx(C,{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:a,variant:"outlined",color:"secondary",children:"Cancel"}),t?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{oe as A};
