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-e972fa8e.js";import{c as d,b as y,u as R}from"./index.esm-b3c20f6d.js";import{o as T}from"./yup-b3178c01.js";import"./GenericThumbnailView-38007944.js";import{F as U}from"./FormInput-dbaa88c2.js";import"./componentStyles-7142291f.js";import"./ScrollableList-4768c2b7.js";import"./TextArea-6c7f39e1.js";import{S as Z}from"./SelectComponent-ef6ff29b.js";import{D as I,a as K}from"./DialogContent-51a7b314.js";import{D as N}from"./DialogTitle-6bcbc606.js";import{D as X}from"./DialogContentText-1562904b.js";import{G as H}from"./Grid2-936c64bd.js";import{D as J}from"./DialogActions-122de1b4.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};
