import{d as N,a as V,b as B,aZ as G,oL as O,r as R,j as r,I as T,aK as U,oM as S,gL as K,gM as X,gN as Z,gO as H,R as h,oN as J,oO as Q}from"./index-e0c07a84.js";import{c as x,b as s,u as W}from"./index.esm-79617ba5.js";import{o as Y}from"./yup-74a95d85.js";import"./GenericThumbnailView-d192caf7.js";import{F as I}from"./FormInput-7bb37f2a.js";import"./componentStyles-5432a72d.js";import"./ScrollableList-874c742d.js";import"./TextArea-e9886f56.js";import{S as _}from"./SelectComponent-5a0ffb58.js";import{D,a as ee}from"./DialogContent-bfc00e3a.js";import{D as re}from"./DialogTitle-d1ec1f1a.js";import{D as te}from"./DialogContentText-c88b94b0.js";import{G as b}from"./Grid2-05f25635.js";import{D as ie}from"./DialogActions-7f92619e.js";const je=({modal:c,closeModal:o,mastersName:q,edit_Id:i,mastersValue:ae})=>{var f;const u=N(),{city:{selectedData:e,pageParams:d},mini:{miniStatesList:P,miniCountryParams:a,miniCountriesList:F,miniCountryLoading:L,miniStatesParams:n,miniStateLoading:z},system:{userAccessList:ne}}=V(t=>({system:B(t),mini:G(t),city:O(t)})),A=x().shape({country:x().shape({label:s().required("Please select country"),value:s().required("Please select country")}).required("Please select country"),state:x().shape({label:s().required("Please select state"),value:s().required("Please select state")}).required("Please select state"),name:s().required("Please enter your city").trim()});R.useEffect(()=>{c?l({name:(e==null?void 0:e.name)||"",country:e!=null&&e.country?{label:e.country.name,value:e.country.id}:null,state:e!=null&&e.state?{label:e.state.name,value:e.state.id}:null}):l()},[c,e]);const{control:p,handleSubmit:$,reset:l,getValues:w}=W({resolver:Y(A),values:{name:e!=null&&e.name?e==null?void 0:e.name:"",country:e!=null&&e.country?{label:e!=null&&e.country?`${e==null?void 0:e.country.name}`:"",value:e!=null&&e.country?`${e==null?void 0:e.country.id}`:""}:null,state:e!=null&&e.state?{label:e!=null&&e.state?`${e==null?void 0:e.state.name}`:"",value:e!=null&&e.state?`${e==null?void 0:e.state.id}`:""}:null}}),M=t=>{var m,j,v,C;if(i==null||i==""){const g={obj:{name:t.name,country_id:(m=t.country)==null?void 0:m.value,state_id:(j=t.state)==null?void 0:j.value},pageParams:d,clearDataFn:()=>{o(),l()},navigate:E=>{}};u(J(g))}else{const g={obj:{id:i,name:t.name,country_id:(v=t.country)==null?void 0:v.value,state_id:(C=t.state)==null?void 0:C.value},pageParams:d,clearDataFn:()=>{o(),l()},navigate:E=>{}};u(Q(g))}},y=w();return r.jsx(r.Fragment,{children:r.jsxs(D,{open:c,onClose:(t,m)=>{m!=="backdropClick"&&o()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(re,{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 ",q,r.jsx(T,{onClick:o,children:r.jsx(U,{color:"white"})})]}),r.jsx(ee,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(te,{id:"alert-dialog-description",sx:{width:500},children:r.jsxs("form",{style:{width:"100%"},onSubmit:$(M),children:[r.jsx(b,{size:{xs:12,md:4},mt:0,children:r.jsx(_,{name:"country",label:"Country",required:!0,control:p,rules:{required:!0},options:F,loading:L,onChange:t=>{u(S(t))},selectParams:{page:a.page,page_size:a.page_size,search:a.search,no_of_pages:a.no_of_pages},hasMore:a.page<a.no_of_pages,fetchapi:K,clearData:X})}),r.jsx(b,{size:{xs:12,md:4},mt:0,children:r.jsx(_,{name:"state",label:"State",required:!0,control:p,rules:{required:!0},options:P,loading:z,onChange:t=>{u(S(t))},selectParams:{page:n.page,page_size:n.page_size,search:n.search,no_of_pages:n.no_of_pages,country:(f=y==null?void 0:y.country)==null?void 0:f.value},hasMore:n.page<n.no_of_pages,fetchapi:Z,clearData:H})}),r.jsx(b,{size:{xs:12,md:4},mt:2,children:r.jsx(I,{sx:{mt:4},name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter City here...",control:p})}),r.jsxs(ie,{sx:{p:2},children:[r.jsx(h,{onClick:o,variant:"outlined",color:"secondary",children:"Cancel"}),i==null||i==""?r.jsx(h,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):r.jsx(h,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})})]})})};export{je as A};
