import{d as y,oR as f,r as k,j as e,I as D,aI as L,B as A,T as S,R as m,oS as C,nD as F,oT as v,oU as w}from"./index-858224db.js";import{c as T,b as d,u as I}from"./index.esm-241dec99.js";import{o as R}from"./yup-9213c3af.js";import"./GenericThumbnailView-2d7b7363.js";import{F as B}from"./FormInput-8eacbbd9.js";import"./componentStyles-107bd37e.js";import{L as E}from"./ScrollableList-bf78e54b.js";import{T as M}from"./TextArea-78cda1eb.js";import{D as z,a as P}from"./DialogContent-e06a39bc.js";import{D as U}from"./DialogTitle-6e616d34.js";import{D as $}from"./DialogContentText-a2775ca2.js";import{G as l}from"./Grid2-274bb638.js";import{D as q}from"./DialogActions-825c19e9.js";const oe=()=>{const o=y(),{departments:{selectedData:r,loading:x,isModelVisible:h,pageParams:c},mini:{miniLocationList:G,miniLocationLoading:V,miniLocationParams:N},system:{userAccessList:W}}=f(),a=()=>{o(C({})),b(),o(F(!1))},t=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(()=>{a()},[]);const{control:p,handleSubmit:j,reset:b}=I({resolver:R(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(U,{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(L,{color:"white"})})]}),e.jsx(P,{sx:{px:"24px",pt:"12px !important",pb:0},children:x?e.jsxs(A,{children:[e.jsx(E,{}),e.jsx(S,{textAlign:"center",children:"Loading..."})]}):e.jsx($,{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(B,{required:!0,name:"name",label:"Name",type:"text",placeholder:"Enter Departments here...",control:p})}),e.jsx(l,{size:{xs:12},children:e.jsx(M,{name:"remarks",label:"Description",type:"text",placeholder:"Write description here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:p})})]}),e.jsxs(q,{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};
