import{d as F,a as L,b as A,a$ as w,qB as E,r as $,j as e,I as k,aM as V,qC as _,i4 as z,U as l,qD as B,op as x,qE as U}from"./index-c3f592b2.js";import{c as d,b as y,u as G}from"./index.esm-70dd1c06.js";import{o as T}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 N}from"./SelectComponent-bc0fff79.js";import{D as R,a as X}from"./DialogContent-b7fc1c43.js";import{D as H}from"./DialogTitle-5d3e2030.js";import{D as J}from"./DialogContentText-c3e782dc.js";import{G as K}from"./Grid2-9e718eb0.js";import{D as M}from"./DialogActions-6e00f4f1.js";const Sr=({modal:u,closeModal:t,mastersName:b,edit_Id:o,mastersValue:O})=>{const a=F(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:Q,miniCountryParams:n,miniCountriesList:p,miniCountryLoading:j,miniCityList:W,miniItemgroupParams:Y,miniStatesParams:Z,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:ir,miniItemgroupLoading:or,countryValue:nr,stateValue:tr},system:{userAccessList:ar}}=L(i=>({system:A(i),mini:w(i),state:E(i)})),S=d().shape({country:d({label:y().required("Please select country"),value:y().required("Please select country")}).required("Please select country"),name:y().required("Please enter your state").trim()});$.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:g,handleSubmit:C,reset:s}=G({resolver:T(S),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}}),v=i=>{var m,h;if(o==null||o==0){const c={obj:{name:i.name,country_id:(m=i.country)==null?void 0:m.value},pageParams:f,clearDataFn:()=>{},navigate:P=>{}};a(B(c)),t(),a(x({})),s()}else{const c={obj:{id:o,name:i.name,country_id:(h=i.country)==null?void 0:h.value},pageParams:{},clearDataFn:()=>{},navigate:P=>{}};a(U(c)),t(),a(x({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(R,{open:u,onClose:(i,m)=>{m!=="backdropClick"&&t()},"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:[o==null||o==0?"Add ":"Update ",b,e.jsx(k,{onClick:t,children:e.jsx(V,{color:"white"})})]}),e.jsx(X,{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:C(v),children:[e.jsx(N,{name:"country",label:"Country",required:!0,control:g,rules:{required:!0},options:p==null?void 0:p.map(i=>({id:i.id,name:i.name})),loading:j,onChange:i=>{a(_(i))},selectParams:{page:n.page,page_size:n.page_size,search:n.search,no_of_pages:n.no_of_pages},hasMore:n.page<n.no_of_pages,fetchapi:z}),e.jsx(K,{size:{xs:12,md:4},mt:2,children:e.jsx(I,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter State here...",control:g})}),e.jsxs(M,{sx:{p:2},children:[e.jsx(l,{onClick:t,variant:"outlined",color:"secondary",children:"Cancel"}),o==null||o==0?e.jsx(l,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):e.jsx(l,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})})]})})};export{Sr as A};
