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-83d9c1e2.js";import{c as d,b as y,u as I}from"./index.esm-82874186.js";import{o as R}from"./yup-dfe9f223.js";import"./GenericThumbnailView-ceecb14e.js";import{F as T}from"./FormInput-03b7722e.js";import"./componentStyles-7858e543.js";import"./ScrollableList-2bb71a63.js";import"./TextArea-7d949f4d.js";import{S as U}from"./SelectComponent-aff7b03c.js";import{D as X,a as N}from"./DialogContent-a75c4d06.js";import{D as H}from"./DialogTitle-3c642f58.js";import{D as J}from"./DialogContentText-ab545101.js";import{G as K}from"./Grid2-78565a55.js";import{D as O}from"./DialogActions-3c3ab24c.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};
