import{d as L,a as F,b as A,a_ as w,qq as _,r as k,j as e,I as E,aL as V,qr as $,i3 as z,R as l,qs as B,oe as x,qt as G}from"./index-e79f7aad.js";import{c as d,b as y,u as R}from"./index.esm-1ca67d65.js";import{o as T}from"./yup-96f14780.js";import"./GenericThumbnailView-8a83a30c.js";import{F as U}from"./FormInput-07daa19d.js";import"./componentStyles-7718fc5e.js";import"./ScrollableList-5929779e.js";import"./TextArea-ec29d1d5.js";import{S as I}from"./SelectComponent-1ba596ac.js";import{D as N,a as X}from"./DialogContent-6a297cef.js";import{D as H}from"./DialogTitle-62595023.js";import{D as J}from"./DialogContentText-0c5306f9.js";import{G as K}from"./Grid2-7786e458.js";import{D as O}from"./DialogActions-edd1d02f.js";const Sr=({modal:u,closeModal:n,mastersName:b,edit_Id:o,mastersValue:Q})=>{const a=L(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:W,miniCountryParams:t,miniCountriesList:p,miniCountryLoading:j,miniCityList:Y,miniItemgroupParams:Z,miniStatesParams:M,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:ir,miniItemgroupLoading:or,countryValue:tr,stateValue:nr},system:{userAccessList:ar}}=F(i=>({system:A(i),mini:w(i),state:_(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()});k.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(o==null||o==0){const c={obj:{name:i.name,country_id:(m=i.country)==null?void 0:m.value},pageParams:f,clearDataFn:()=>{},navigate:P=>{}};a(B(c)),n(),a(x({})),s()}else{const c={obj:{id:o,name:i.name,country_id:(h=i.country)==null?void 0:h.value},pageParams:{},clearDataFn:()=>{},navigate:P=>{}};a(G(c)),n(),a(x({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(N,{open:u,onClose:(i,m)=>{m!=="backdropClick"&&n()},"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:[o==null||o==0?"Add ":"Update ",b,e.jsx(E,{onClick:n,children:e.jsx(V,{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(I,{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:t.page,page_size:t.page_size,search:t.search,no_of_pages:t.no_of_pages},hasMore:t.page<t.no_of_pages,fetchapi:z}),e.jsx(K,{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(O,{sx:{p:2},children:[e.jsx(l,{onClick:n,variant:"outlined",color:"secondary",children:"Cancel"}),o==null||o==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};
