import{d as F,a as q,b as A,a_ as w,pS as V,r as _,j as e,I as k,aL as z,pT as E,hz as $,R as l,pU as T,nI as x,pV as U}from"./index-952e178b.js";import{c as d,b as y,u as B}from"./index.esm-6feddb16.js";import{o as G}from"./yup-d92565dd.js";import"./GenericThumbnailView-4e535459.js";import{F as I}from"./FormInput-8320115a.js";import"./componentStyles-00160cc0.js";import"./ScrollableList-cd5816a8.js";import"./TextArea-ce7716c9.js";import{S as R}from"./SelectComponent-16c4ed7a.js";import{D as N,a as X}from"./DialogContent-4facb916.js";import{D as H}from"./DialogTitle-3aa960f8.js";import{D as J}from"./DialogContentText-54d95680.js";import{G as K}from"./Grid2-7b742c2a.js";import{D as O}from"./DialogActions-bd200b72.js";const Sr=({modal:u,closeModal:t,mastersName:b,edit_Id:n,mastersValue:Q})=>{const a=F(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:W,miniCountryParams:o,miniCountriesList:p,miniCountryLoading:j,miniCityList:Y,miniItemgroupParams:Z,miniStatesParams:M,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:ir,miniItemgroupLoading:nr,countryValue:or,stateValue:tr},system:{userAccessList:ar}}=q(i=>({system:A(i),mini:w(i),state:V(i)})),S=d().shape({country:d({label:y().required("Please select country"),value:y().required("Please select country")}).required("Please select country"),name:y().required("Please enter your state").trim()});_.useEffect(()=>{u?s({name:(r==null?void 0:r.name)||"",country:r!=null&&r.country?{label:r==null?void 0:r.country.name,value:r==null?void 0:r.country.id}:null}):s()},[u,r]);const{control:g,handleSubmit:v,reset:s}=B({resolver:G(S),values:{name:r!=null&&r.name?r==null?void 0:r.name:"",country:r!=null&&r.country?{label:r!=null&&r.country?`${r==null?void 0:r.country.name}`:"",value:r!=null&&r.country?`${r==null?void 0:r.country.id}`:""}:null}}),C=i=>{var m,h;if(n==null||n==0){const c={obj:{name:i.name,country_id:(m=i.country)==null?void 0:m.value},pageParams:f,clearDataFn:()=>{},navigate:L=>{}};a(T(c)),t(),a(x({})),s()}else{const c={obj:{id:n,name:i.name,country_id:(h=i.country)==null?void 0:h.value},pageParams:{},clearDataFn:()=>{},navigate:L=>{}};a(U(c)),t(),a(x({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(N,{open:u,onClose:(i,m)=>{m!=="backdropClick"&&t()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(H,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[n==null||n==0?"Add ":"Update ",b,e.jsx(k,{onClick:t,children:e.jsx(z,{color:"white"})})]}),e.jsx(X,{sx:{px:"24px",pt:"12px !important",pb:0},children:e.jsx(J,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:v(C),children:[e.jsx(R,{name:"country",label:"Country",required:!0,control:g,rules:{required:!0},options:p==null?void 0:p.map(i=>({id:i.id,name:i.name})),loading:j,onChange:i=>{a(E(i))},selectParams:{page:o.page,page_size:o.page_size,search:o.search,no_of_pages:o.no_of_pages},hasMore:o.page<o.no_of_pages,fetchapi:$}),e.jsx(K,{size:{xs:12,md:4},mt:2,children:e.jsx(I,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter State here...",control:g})}),e.jsxs(O,{sx:{p:2},children:[e.jsx(l,{onClick:t,variant:"outlined",color:"secondary",children:"Cancel"}),n==null||n==0?e.jsx(l,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):e.jsx(l,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})})]})})};export{Sr as A};
