import{d as L,a as q,b as A,aZ as w,pb as _,r as k,j as e,I as E,aK as V,pc as $,g_ as z,R as l,pd as B,n0 as x,pe as G}from"./index-6f149d0c.js";import{c as d,b as y,u as R}from"./index.esm-88773116.js";import{o as T}from"./yup-7ebcc99d.js";import"./GenericThumbnailView-01fef5a2.js";import{F as U}from"./FormInput-d3efc191.js";import"./componentStyles-d6393a0a.js";import"./ScrollableList-e382be10.js";import"./TextArea-eb0beb3a.js";import{S as I}from"./SelectComponent-ff450e8a.js";import{D as K}from"./Dialog-4a8f5dd6.js";import{D as N}from"./DialogTitle-0edc620d.js";import{D as X}from"./DialogContent-398aea0b.js";import{D as Z}from"./DialogContentText-12f15d60.js";import{G as H}from"./Grid2-3d1a13f9.js";import{D as J}from"./DialogActions-d3c730f9.js";const vr=({modal:u,closeModal:t,mastersName:b,edit_Id:o,mastersValue:O})=>{const a=L(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:Q,miniCountryParams:n,miniCountriesList:p,miniCountryLoading:j,miniCityList:W,miniItemgroupParams:Y,miniStatesParams:M,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:ir,miniItemgroupLoading:or,countryValue:nr,stateValue:tr},system:{userAccessList:ar}}=q(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:F=>{}};a(B(c)),t(),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:F=>{}};a(G(c)),t(),a(x({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(K,{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:[o==null||o==0?"Add ":"Update ",b,e.jsx(E,{onClick:t,children:e.jsx(V,{color:"white"})})]}),e.jsx(X,{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(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: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(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"}),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{vr as A};
