import{d as V,a as B,b as G,aM as T,nI as U,r as J,j as r,I as K,ax as N,nJ as S,fY as R,fZ as X,f_ as Y,f$ as Z,z as h,nK as H,nL as O}from"./index-c5c88b67.js";import{c as x,b as o,u as Q}from"./index.esm-81620445.js";import{o as W}from"./yup-41605283.js";import"./GenericThumbnailView-43782201.js";import{F as I}from"./FormInput-86f14880.js";import"./componentStyles-a5e5a830.js";import"./ScrollableList-21ab2b9c.js";import"./TextArea-aad9dffe.js";import{S as _}from"./SelectComponent-8c888daa.js";import{D,a as ee}from"./DialogContent-1350b249.js";import{D as re}from"./DialogTitle-da236dcc.js";import{D as te}from"./DialogContentText-659ecbc3.js";import{G as b}from"./Grid2-0ff60c92.js";import{D as ie}from"./DialogActions-1232a7fa.js";const je=({modal:c,closeModal:s,mastersName:q,edit_Id:i,mastersValue:ne})=>{var d;const u=V(),{city:{selectedData:e,pageParams:f},mini:{miniStatesList:P,miniCountryParams:n,miniCountriesList:z,miniCountryLoading:F,miniStatesParams:a,miniStateLoading:A},system:{userAccessList:ae}}=B(t=>({system:G(t),mini:T(t),city:U(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()});J.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}=Q({resolver:W(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 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:f,clearDataFn:()=>{s(),l()},navigate:M=>{}};u(H(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:f,clearDataFn:()=>{s(),l()},navigate:M=>{}};u(O(g))}},y=w();return r.jsx(r.Fragment,{children:r.jsxs(D,{open:c,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(K,{onClick:s,children:r.jsx(N,{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:$(k),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:z,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},hasMore:n.page<n.no_of_pages,fetchapi:R,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: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,country:(d=y==null?void 0:y.country)==null?void 0:d.value},hasMore:a.page<a.no_of_pages,fetchapi:Y,clearData:Z})}),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:s,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};
