import{b as V,r as j,a as $,h as E,er as T,j7 as _,j as e,I as f,ec as k,Q as m,j8 as N,iN as B,f3 as I,K as p,j9 as U,ja as b,jb as G}from"./index-76d4793e.js";import{c as C,b as y}from"./index.esm-ad8a7c9f.js";import{o as K}from"./yup-688ec4f6.js";import{u as M}from"./index.esm-3adfd9f7.js";import"./componentStyles-0803b39e.js";import{F as O}from"./FormInput-8f40ded1.js";/* empty css                   */import"./ScrollableList-4dae3697.js";import{S as Q}from"./SelectComponent-3c1140e6.js";import{A as R}from"./add.country-18f95a67.js";import{D as X,a as Z}from"./DialogContent-7bd8dd8f.js";import{D as H}from"./DialogTitle-71dd5b3a.js";import{D as J}from"./DialogContentText-7642f81f.js";import{T as W}from"./Tooltip-0a59b9eb.js";import{D as Y}from"./DialogActions-5a5e1db9.js";const Fr=({modal:u,closeModal:i,mastersName:S,edit_Id:n,mastersValue:D})=>{const a=V(),[v,h]=j.useState(!1),{state:{selectedData:r,pageParams:P},mini:{miniStatesList:rr,miniCountryParams:o,miniCountriesList:l,miniCountryLoading:A,miniCityList:er,miniItemgroupParams:tr,miniStatesParams:nr,miniStateLoading:or,miniCityParams:ir,miniCityLoading:ar,miniItemgroupList:sr,miniItemgroupLoading:mr,countryValue:ur,stateValue:lr},system:{userAccessList:cr}}=$(t=>({system:E(t),mini:T(t),state:_(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:(r==null?void 0:r.name)||"",country:r!=null&&r.country?{label:r==null?void 0:r.country.name,value:r==null?void 0:r.country.id}:null}):s()},[u,r]);const{control:x,handleSubmit:F,reset:s}=M({resolver:K(L),values:{name:r!=null&&r.name?r==null?void 0:r.name:"",country:r!=null&&r.country?{label:r!=null&&r.country?`${r==null?void 0:r.country.name}`:"",value:r!=null&&r.country?`${r==null?void 0:r.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(G(c)),i(),a(b({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(X,{open:u,onClose:i,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.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,e.jsx(f,{onClick:i,children:e.jsx(k,{color:"white"})})]}),e.jsx(Z,{sx:{px:"24px",pt:"12px !important",pb:0},children:e.jsx(J,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:F(q),children:[e.jsxs(m,{container:!0,alignItems:"center",children:[e.jsx(m,{size:{xs:11},children:e.jsx(Q,{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(N(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:B})}),e.jsx(m,{size:{xs:1},mt:3,children:e.jsx(W,{title:"Add Country",children:e.jsx(f,{onClick:()=>{h(!0)},children:e.jsx(I,{})})})})]}),e.jsx(m,{size:{xs:12,md:4},mt:2,children:e.jsx(O,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter State here...",control:x})}),e.jsxs(Y,{sx:{p:2},children:[e.jsx(p,{onClick:i,variant:"outlined",color:"secondary",children:"Cancel"}),n==null||n==0?e.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):e.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})}),e.jsx(R,{modal:v,closeModal:()=>h(!1),mastersName:"Country",mastersValue:""})]})})};export{Fr as A};
