import{d as F,a as q,b as A,aZ as w,p8 as k,r as E,j as e,I as V,aK as _,p9 as $,gL as z,R as l,pa as B,mZ as x,pb as G}from"./index-e0c07a84.js";import{c as d,b as y,u as R}from"./index.esm-79617ba5.js";import{o as T}from"./yup-74a95d85.js";import"./GenericThumbnailView-d192caf7.js";import{F as U}from"./FormInput-7bb37f2a.js";import"./componentStyles-5432a72d.js";import"./ScrollableList-874c742d.js";import"./TextArea-e9886f56.js";import{S as Z}from"./SelectComponent-5a0ffb58.js";import{D as I,a as K}from"./DialogContent-bfc00e3a.js";import{D as N}from"./DialogTitle-d1ec1f1a.js";import{D as X}from"./DialogContentText-c88b94b0.js";import{G as H}from"./Grid2-05f25635.js";import{D as J}from"./DialogActions-7f92619e.js";const Sr=({modal:u,closeModal:t,mastersName:b,edit_Id:n,mastersValue:O})=>{const a=F(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:Q,miniCountryParams:o,miniCountriesList:p,miniCountryLoading:j,miniCityList:W,miniItemgroupParams:Y,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:k(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()});E.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}=R({resolver:T(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(B(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(G(c)),t(),a(x({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(I,{open:u,onClose:(i,m)=>{m!=="backdropClick"&&t()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(N,{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(V,{onClick:t,children:e.jsx(_,{color:"white"})})]}),e.jsx(K,{sx:{px:"24px",pt:"12px !important",pb:0},children:e.jsx(X,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:v(C),children:[e.jsx(Z,{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($(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:z}),e.jsx(H,{size:{xs:12,md:4},mt:2,children:e.jsx(U,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter State here...",control:g})}),e.jsxs(J,{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};
