import{d as L,a as q,b as A,aX as w,og as k,r as E,j as e,I as V,aI as _,oh as $,g5 as z,R as l,oi as B,m5 as x,oj as G}from"./index-3141de2d.js";import{c as d,b as y,u as I}from"./index.esm-8b0c9a99.js";import{o as R}from"./yup-c2fea6fa.js";import"./GenericThumbnailView-c2621934.js";import{F as T}from"./FormInput-abff9e70.js";import"./componentStyles-24f97919.js";import"./ScrollableList-fa62971d.js";import"./TextArea-ceaff311.js";import{S as U}from"./SelectComponent-90299b7f.js";import{D as X,a as N}from"./DialogContent-17781b67.js";import{D as H}from"./DialogTitle-16416764.js";import{D as J}from"./DialogContentText-c64ca110.js";import{G as K}from"./Grid2-488bb30d.js";import{D as O}from"./DialogActions-37bf04e2.js";const Sr=({modal:u,closeModal:t,mastersName:b,edit_Id:i,mastersValue:Q})=>{const a=L(),{state:{selectedData:r,pageParams:j},mini:{miniStatesList:W,miniCountryParams:n,miniCountriesList:p,miniCountryLoading:f,miniCityList:Y,miniItemgroupParams:Z,miniStatesParams:M,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()});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}=I({resolver:R(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,h;if(i==null||i==0){const c={obj:{name:o.name,country_id:(m=o.country)==null?void 0:m.value},pageParams:j,clearDataFn:()=>{},navigate:F=>{}};a(B(c)),t(),a(x({})),s()}else{const c={obj:{id:i,name:o.name,country_id:(h=o.country)==null?void 0:h.value},pageParams:{},clearDataFn:()=>{},navigate:F=>{}};a(G(c)),t(),a(x({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(X,{open:u,onClose:(o,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:[i==null||i==0?"Add ":"Update ",b,e.jsx(V,{onClick:t,children:e.jsx(_,{color:"white"})})]}),e.jsx(N,{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(U,{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:f,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:z}),e.jsx(K,{size:{xs:12,md:4},mt:2,children:e.jsx(T,{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"}),i==null||i==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};
