import{d as M,a as V,b as G,a_ as R,pt as T,r as U,j as r,I as N,aL as X,pu as S,hz as H,hA as J,hB as K,hC as O,R as g,pv as Q,pw as W}from"./index-952e178b.js";import{c as x,b as o,u as Y}from"./index.esm-6feddb16.js";import{o as Z}from"./yup-d92565dd.js";import"./GenericThumbnailView-4e535459.js";import{F as I}from"./FormInput-8320115a.js";import"./componentStyles-00160cc0.js";import"./ScrollableList-cd5816a8.js";import"./TextArea-ce7716c9.js";import{S as _}from"./SelectComponent-16c4ed7a.js";import{D,a as ee}from"./DialogContent-4facb916.js";import{D as re}from"./DialogTitle-3aa960f8.js";import{D as te}from"./DialogContentText-54d95680.js";import{G as b}from"./Grid2-7b742c2a.js";import{D as ie}from"./DialogActions-bd200b72.js";const je=({modal:p,closeModal:s,mastersName:q,edit_Id:i,mastersValue:ae})=>{var f;const u=M(),{city:{selectedData:e,pageParams:d},mini:{miniStatesList:P,miniCountryParams:a,miniCountriesList:z,miniCountryLoading:A,miniStatesParams:n,miniStateLoading:F},system:{userAccessList:ne}}=V(t=>({system:G(t),mini:R(t),city:T(t)})),L=x().shape({country:x().shape({label:o().required("Please select country"),value:o().required("Please select country")}).required("Please select country"),state:x().shape({label:o().required("Please select state"),value:o().required("Please select state")}).required("Please select state"),name:o().required("Please enter your city").trim()});U.useEffect(()=>{p?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()},[p,e]);const{control:c,handleSubmit:w,reset:l,getValues:$}=Y({resolver:Z(L),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}}),k=t=>{var m,j,v,C;if(i==null||i==""){const h={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:()=>{s(),l()},navigate:B=>{}};u(Q(h))}else{const h={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:()=>{s(),l()},navigate:B=>{}};u(W(h))}},y=$();return r.jsx(r.Fragment,{children:r.jsxs(D,{open:p,onClose:(t,m)=>{m!=="backdropClick"&&s()},"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(N,{onClick:s,children:r.jsx(X,{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:w(k),children:[r.jsx(b,{size:{xs:12,md:4},mt:0,children:r.jsx(_,{name:"country",label:"Country",required:!0,control:c,rules:{required:!0},options:z,loading:A,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:H,clearData:J})}),r.jsx(b,{size:{xs:12,md:4},mt:0,children:r.jsx(_,{name:"state",label:"State",required:!0,control:c,rules:{required:!0},options:P,loading:F,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:K,clearData:O})}),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:c})}),r.jsxs(ie,{sx:{p:2},children:[r.jsx(g,{onClick:s,variant:"outlined",color:"secondary",children:"Cancel"}),i==null||i==""?r.jsx(g,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):r.jsx(g,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})})]})})};export{je as A};
