import{d as y,qV as f,r as k,j as e,I as D,aM as L,B as A,T as F,U as m,qW as C,pF as S,qX as v,qY as w}from"./index-c3f592b2.js";import{c as q,b as d,u as T}from"./index.esm-70dd1c06.js";import{o as I}from"./yup-abb4a026.js";import"./GenericThumbnailView-9f1d2f81.js";import{F as M}from"./FormInput-adbf55b1.js";import"./componentStyles-b8fcedb5.js";import{L as B}from"./ScrollableList-ecbfc0f3.js";import{T as E}from"./TextArea-674a9ec6.js";import{D as z,a as P}from"./DialogContent-b7fc1c43.js";import{D as R}from"./DialogTitle-5d3e2030.js";import{D as U}from"./DialogContentText-c3e782dc.js";import{G as l}from"./Grid2-9e718eb0.js";import{D as V}from"./DialogActions-6e00f4f1.js";const te=()=>{const t=y(),{departments:{selectedData:r,loading:x,isModelVisible:h,pageParams:c},mini:{miniLocationList:$,miniLocationLoading:G,miniLocationParams:W},system:{userAccessList:X}}=f(),a=()=>{t(C({})),b(),t(S(!1))},i=r==null?void 0:r.id,u=q().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:I(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(i){const n={obj:{id:i,name:s.name,remarks:s.remarks},pageParams:c,clearDataFn:()=>{a()}};t(w(n))}else{const n={obj:{name:s.name,remarks:s.remarks},pageParams:c,clearDataFn:()=>{a()}};t(v(n))}};return e.jsx(e.Fragment,{children:e.jsxs(z,{open:h,onClose:(s,o)=>{o!=="backdropClick"&&a()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(R,{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:a,children:e.jsx(L,{color:"white"})})]}),e.jsx(P,{sx:{px:"24px",pt:"12px !important",pb:0},children:x?e.jsxs(A,{children:[e.jsx(B,{}),e.jsx(F,{textAlign:"center",children:"Loading..."})]}):e.jsx(U,{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(M,{required:!0,name:"name",label:"Name",type:"text",placeholder:"Enter Departments here...",control:p})}),e.jsx(l,{size:{xs:12},children:e.jsx(E,{name:"remarks",label:"Description",type:"text",placeholder:"Write description here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:p})})]}),e.jsxs(V,{sx:{p:2},children:[e.jsx(m,{onClick:a,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{te as A};
