import{d as V,a as B,b as G,aZ as N,oN as R,r as T,j as r,I as U,aK as Z,oO as S,gZ as K,g_ as O,g$ as Q,h0 as X,R as h,oP as H,oQ as J}from"./index-e6164346.js";import{c as x,b as s,u as W}from"./index.esm-0a041314.js";import{o as Y}from"./yup-5fd5d57b.js";import"./GenericThumbnailView-80c6fd98.js";import{F as I}from"./FormInput-859198ec.js";import"./componentStyles-00385170.js";import"./ScrollableList-5a17e8f4.js";import"./TextArea-f5c200de.js";import{S as _}from"./SelectComponent-3cac02a3.js";import{D}from"./Dialog-2e8a8e2e.js";import{D as ee}from"./DialogTitle-8757f50f.js";import{D as re}from"./DialogContent-f10d6731.js";import{D as te}from"./DialogContentText-027be15d.js";import{G as b}from"./Grid2-c9c87842.js";import{D as ie}from"./DialogActions-31bec80e.js";const ve=({modal:c,closeModal:n,mastersName:P,edit_Id:i,mastersValue:oe})=>{var f;const u=V(),{city:{selectedData:e,pageParams:d},mini:{miniStatesList:q,miniCountryParams:o,miniCountriesList:F,miniCountryLoading:z,miniStatesParams:a,miniStateLoading:A},system:{userAccessList:ae}}=B(t=>({system:G(t),mini:N(t),city:R(t)})),$=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()});T.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:L,reset:l,getValues:w}=W({resolver:Y($),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:d,clearDataFn:()=>{n(),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:d,clearDataFn:()=>{n(),l()},navigate:M=>{}};u(J(g))}},y=w();return r.jsx(r.Fragment,{children:r.jsxs(D,{open:c,onClose:(t,m)=>{m!=="backdropClick"&&n()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(ee,{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 ",P,r.jsx(U,{onClick:n,children:r.jsx(Z,{color:"white"})})]}),r.jsx(re,{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:L(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:F,loading:z,onChange:t=>{u(S(t))},selectParams:{page:o.page,page_size:o.page_size,search:o.search,no_of_pages:o.no_of_pages},hasMore:o.page<o.no_of_pages,fetchapi:K,clearData:O})}),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:q,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:(f=y==null?void 0:y.country)==null?void 0:f.value},hasMore:a.page<a.no_of_pages,fetchapi:Q,clearData:X})}),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:n,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{ve as A};
