import{b as V,r as j,a as $,h as k,ez as E,jj as T,j as r,I as f,ec as _,Q as m,jk as B,iZ as I,fe as N,K as p,jl as U,jm as b,jn as Z}from"./index-43bf7a1c.js";import{c as C,b as y}from"./index.esm-f9e0a906.js";import{o as G}from"./yup-3b80ed10.js";import{u as K}from"./index.esm-0548c843.js";import"./componentStyles-4624000e.js";import{F as M}from"./FormInput-33b720a4.js";/* empty css                   */import"./ScrollableList-e19132c3.js";import{S as O}from"./SelectComponent-84e66b0a.js";import{A as Q}from"./add.country-413dbb22.js";import{D as R,a as X}from"./DialogContent-d5902709.js";import{D as H}from"./DialogTitle-20dc6f66.js";import{D as J}from"./DialogContentText-abf03c9f.js";import{T as W}from"./Tooltip-c7371fbe.js";import{D as Y}from"./DialogActions-d63c6496.js";const Fe=({modal:u,closeModal:i,mastersName:S,edit_Id:n,mastersValue:D})=>{const a=V(),[v,h]=j.useState(!1),{state:{selectedData:e,pageParams:P},mini:{miniStatesList:ee,miniCountryParams:o,miniCountriesList:l,miniCountryLoading:A,miniCityList:re,miniItemgroupParams:te,miniStatesParams:ne,miniStateLoading:oe,miniCityParams:ie,miniCityLoading:ae,miniItemgroupList:se,miniItemgroupLoading:me,countryValue:ue,stateValue:le},system:{userAccessList:ce}}=$(t=>({system:k(t),mini:E(t),state:T(t)})),L=C().shape({country:C({label:y().required("Please select country"),value:y().required("Please select country")}).required("Please select country"),name:y().required("Please enter your state").trim().matches(/^[a-zA-Z0-9 ]*$/,"state name should not contain special characters")});j.useEffect(()=>{u?s({name:(e==null?void 0:e.name)||"",country:e!=null&&e.country?{label:e==null?void 0:e.country.name,value:e==null?void 0:e.country.id}:null}):s()},[u,e]);const{control:x,handleSubmit:F,reset:s}=K({resolver:G(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}}),q=t=>{var d,g;if(n==null||n==0){const c={obj:{name:t.name,country_id:(d=t.country)==null?void 0:d.value},pageParams:P,clearDataFn:()=>{},navigate:w=>{}};a(U(c)),i(),a(b({})),s()}else{const c={obj:{id:n,name:t.name,country_id:(g=t.country)==null?void 0:g.value},pageParams:{},clearDataFn:()=>{},navigate:w=>{}};a(Z(c)),i(),a(b({})),s()}};return r.jsx(r.Fragment,{children:r.jsxs(R,{open:u,onClose:i,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(H,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[n==null||n==0?"Add ":"Update ",S,r.jsx(f,{onClick:i,children:r.jsx(_,{color:"white"})})]}),r.jsx(X,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(J,{id:"alert-dialog-description",sx:{width:500},children:r.jsxs("form",{style:{width:"100%"},onSubmit:F(q),children:[r.jsxs(m,{container:!0,alignItems:"center",children:[r.jsx(m,{size:{xs:11},children:r.jsx(O,{name:"country",label:"Country",required:!0,control:x,rules:{required:!0},options:l==null?void 0:l.map(t=>({id:t.id,name:t.name})),loading:A,onChange:t=>{a(B(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:I})}),r.jsx(m,{size:{xs:1},mt:3,children:r.jsx(W,{title:"Add Country",children:r.jsx(f,{onClick:()=>{h(!0)},children:r.jsx(N,{})})})})]}),r.jsx(m,{size:{xs:12,md:4},mt:2,children:r.jsx(M,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter State here...",control:x})}),r.jsxs(Y,{sx:{p:2},children:[r.jsx(p,{onClick:i,variant:"outlined",color:"secondary",children:"Cancel"}),n==null||n==0?r.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):r.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})}),r.jsx(Q,{modal:v,closeModal:()=>h(!1),mastersName:"Country",mastersValue:""})]})})};export{Fe as A};
