import{d as U,a as V,b as B,a$ as G,qa as T,r as N,j as r,I as R,aM as X,qb as S,i4 as H,i5 as J,i6 as K,i7 as O,U as h,qc as Q,qd as W}from"./index-c3f592b2.js";import{c as x,b as o,u as Y}from"./index.esm-70dd1c06.js";import{o as Z}from"./yup-abb4a026.js";import"./GenericThumbnailView-9f1d2f81.js";import{F as I}from"./FormInput-adbf55b1.js";import"./componentStyles-b8fcedb5.js";import"./ScrollableList-ecbfc0f3.js";import"./TextArea-674a9ec6.js";import{S as q}from"./SelectComponent-bc0fff79.js";import{D,a as ee}from"./DialogContent-b7fc1c43.js";import{D as re}from"./DialogTitle-5d3e2030.js";import{D as ie}from"./DialogContentText-c3e782dc.js";import{G as b}from"./Grid2-9e718eb0.js";import{D as te}from"./DialogActions-6e00f4f1.js";const je=({modal:c,closeModal:s,mastersName:_,edit_Id:t,mastersValue:ae})=>{var f;const u=U(),{city:{selectedData:e,pageParams:d},mini:{miniStatesList:P,miniCountryParams:a,miniCountriesList:F,miniCountryLoading:z,miniStatesParams:n,miniStateLoading:A},system:{userAccessList:ne}}=V(i=>({system:B(i),mini:G(i),city:T(i)})),$=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()});N.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}=Y({resolver:Z($),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=i=>{var m,j,v,C;if(t==null||t==""){const g={obj:{name:i.name,country_id:(m=i.country)==null?void 0:m.value,state_id:(j=i.state)==null?void 0:j.value},pageParams:d,clearDataFn:()=>{s(),l()},navigate:M=>{}};u(Q(g))}else{const g={obj:{id:t,name:i.name,country_id:(v=i.country)==null?void 0:v.value,state_id:(C=i.state)==null?void 0:C.value},pageParams:d,clearDataFn:()=>{s(),l()},navigate:M=>{}};u(W(g))}},y=w();return r.jsx(r.Fragment,{children:r.jsxs(D,{open:c,onClose:(i,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:[t==null||t==0?"Add ":"Update ",_,r.jsx(R,{onClick:s,children:r.jsx(X,{color:"white"})})]}),r.jsx(ee,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(ie,{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(q,{name:"country",label:"Country",required:!0,control:p,rules:{required:!0},options:F,loading:z,onChange:i=>{u(S(i))},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(q,{name:"state",label:"State",required:!0,control:p,rules:{required:!0},options:P,loading:A,onChange:i=>{u(S(i))},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:p})}),r.jsxs(te,{sx:{p:2},children:[r.jsx(h,{onClick:s,variant:"outlined",color:"secondary",children:"Cancel"}),t==null||t==""?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};
