import{d as L,a as q,b as A,aM as w,o5 as k,r as z,j as e,I as E,ax as V,o6 as _,fZ as $,z as c,o7 as B,lO as h,o8 as G}from"./index-4dfc510b.js";import{c as d,b as y,u as T}from"./index.esm-0a454763.js";import{o as U}from"./yup-80def618.js";import"./GenericThumbnailView-6256cad7.js";import{F as I}from"./FormInput-f887e69c.js";import"./componentStyles-df94248d.js";import"./ScrollableList-bef4a518.js";import"./TextArea-a0cc14f3.js";import{S as N}from"./SelectComponent-bfde3322.js";import{D as O,a as R}from"./DialogContent-3bf4ff27.js";import{D as X}from"./DialogTitle-248b1818.js";import{D as Z}from"./DialogContentText-a6ab23a2.js";import{G as H}from"./Grid2-713975b3.js";import{D as J}from"./DialogActions-49286e71.js";const Sr=({modal:u,closeModal:t,mastersName:b,edit_Id:i,mastersValue:K})=>{const a=L(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:M,miniCountryParams:n,miniCountriesList:p,miniCountryLoading:j,miniCityList:Q,miniItemgroupParams:W,miniStatesParams:Y,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:or,miniItemgroupLoading:ir,countryValue:nr,stateValue:tr},system:{userAccessList:ar}}=q(o=>({system:A(o),mini:w(o),state:k(o)})),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()});z.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}=T({resolver:U(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=o=>{var m,x;if(i==null||i==0){const l={obj:{name:o.name,country_id:(m=o.country)==null?void 0:m.value},pageParams:f,clearDataFn:()=>{},navigate:F=>{}};a(B(l)),t(),a(h({})),s()}else{const l={obj:{id:i,name:o.name,country_id:(x=o.country)==null?void 0:x.value},pageParams:{},clearDataFn:()=>{},navigate:F=>{}};a(G(l)),t(),a(h({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(O,{open:u,onClose:(o,m)=>{m!=="backdropClick"&&t()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(X,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[i==null||i==0?"Add ":"Update ",b,e.jsx(E,{onClick:t,children:e.jsx(V,{color:"white"})})]}),e.jsx(R,{sx:{px:"24px",pt:"12px !important",pb:0},children:e.jsx(Z,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:v(C),children:[e.jsx(N,{name:"country",label:"Country",required:!0,control:g,rules:{required:!0},options:p==null?void 0:p.map(o=>({id:o.id,name:o.name})),loading:j,onChange:o=>{a(_(o))},selectParams:{page:n.page,page_size:n.page_size,search:n.search,no_of_pages:n.no_of_pages},hasMore:n.page<n.no_of_pages,fetchapi:$}),e.jsx(H,{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(J,{sx:{p:2},children:[e.jsx(c,{onClick:t,variant:"outlined",color:"secondary",children:"Cancel"}),i==null||i==0?e.jsx(c,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):e.jsx(c,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})})]})})};export{Sr as A};
