import{d as L,a as q,b as A,aZ as w,pa as $,r as k,j as e,I as E,aK as V,pb as _,gZ as z,R as l,pc as B,m$ as x,pd as G}from"./index-e6164346.js";import{c as d,b as y,u as R}from"./index.esm-0a041314.js";import{o as T}from"./yup-5fd5d57b.js";import"./GenericThumbnailView-80c6fd98.js";import{F as U}from"./FormInput-859198ec.js";import"./componentStyles-00385170.js";import"./ScrollableList-5a17e8f4.js";import"./TextArea-f5c200de.js";import{S as Z}from"./SelectComponent-3cac02a3.js";import{D as I}from"./Dialog-2e8a8e2e.js";import{D as K}from"./DialogTitle-8757f50f.js";import{D as N}from"./DialogContent-f10d6731.js";import{D as X}from"./DialogContentText-027be15d.js";import{G as H}from"./Grid2-c9c87842.js";import{D as J}from"./DialogActions-31bec80e.js";const vr=({modal:u,closeModal:n,mastersName:b,edit_Id:o,mastersValue:O})=>{const a=L(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:Q,miniCountryParams:t,miniCountriesList:p,miniCountryLoading:j,miniCityList:W,miniItemgroupParams:Y,miniStatesParams:M,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:ir,miniItemgroupLoading:or,countryValue:tr,stateValue:nr},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)),n(),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)),n(),a(x({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(I,{open:u,onClose:(i,m)=>{m!=="backdropClick"&&n()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(K,{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:n,children:e.jsx(V,{color:"white"})})]}),e.jsx(N,{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:t.page,page_size:t.page_size,search:t.search,no_of_pages:t.no_of_pages},hasMore:t.page<t.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:n,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};
