import{b as V,r as j,a as _,g as $,eu as E,jc as T,j as r,I as f,ef as k,P as m,jd as B,i_ as I,f7 as N,J as p,je as U,jf as b,jg as G}from"./index-d2b25495.js";import{c as C,b as y}from"./index.esm-3043d6d4.js";import{o as J}from"./yup-267e586f.js";import{u as M}from"./index.esm-ce3c2c20.js";import"./componentStyles-0e851d91.js";import{F as O}from"./FormInput-d202e905.js";/* empty css                   */import"./ScrollableList-fc1de312.js";import{S as R}from"./SelectComponent-d286bfef.js";import{A as X}from"./add.country-b0333636.js";import{D as Z,a as H}from"./DialogContent-cded694d.js";import{D as K}from"./DialogTitle-a145b392.js";import{D as Q}from"./DialogContentText-43575e44.js";import{T as W}from"./Tooltip-82372cdb.js";import{D as Y}from"./DialogActions-7c802cc8.js";const Fe=({modal:u,closeModal:i,mastersName:S,edit_Id:n,mastersValue:D})=>{const a=V(),[v,d]=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:$(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}=M({resolver:J(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 h,g;if(n==null||n==0){const c={obj:{name:t.name,country_id:(h=t.country)==null?void 0:h.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(G(c)),i(),a(b({})),s()}};return r.jsx(r.Fragment,{children:r.jsxs(Z,{open:u,onClose:i,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(K,{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(k,{color:"white"})})]}),r.jsx(H,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(Q,{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(R,{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:()=>{d(!0)},children:r.jsx(N,{})})})})]}),r.jsx(m,{size:{xs:12,md:4},mt:2,children:r.jsx(O,{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(X,{modal:v,closeModal:()=>d(!1),mastersName:"Country",mastersValue:""})]})})};export{Fe as A};
