import{d as F,a as L,b as q,aX as w,ox as k,r as z,j as e,I as E,aI as V,oy as _,gc as $,R as l,oz as B,mm as h,oA as G}from"./index-0698dbe6.js";import{c as d,b as y,u as I}from"./index.esm-85d015f3.js";import{o as R}from"./yup-7a53beb8.js";import"./GenericThumbnailView-dca658f3.js";import{F as T}from"./FormInput-98c39817.js";import"./componentStyles-91278318.js";import"./ScrollableList-fc87149c.js";import"./TextArea-91c96faf.js";import{S as U}from"./SelectComponent-fbded912.js";import{D as X,a as N}from"./DialogContent-6dbfd908.js";import{D as H}from"./DialogTitle-a8d1726a.js";import{D as J}from"./DialogContentText-ceb40f80.js";import{G as K}from"./Grid2-a3850bef.js";import{D as O}from"./DialogActions-318201e3.js";const Sr=({modal:u,closeModal:t,mastersName:b,edit_Id:i,mastersValue:Q})=>{const a=F(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:W,miniCountryParams:n,miniCountriesList:p,miniCountryLoading:j,miniCityList:Y,miniItemgroupParams:Z,miniStatesParams:M,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:or,miniItemgroupLoading:ir,countryValue:nr,stateValue:tr},system:{userAccessList:ar}}=L(o=>({system:q(o),mini:w(o),state:k(o)})),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()});z.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:v,reset:s}=I({resolver:R(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}}),C=o=>{var m,x;if(i==null||i==0){const c={obj:{name:o.name,country_id:(m=o.country)==null?void 0:m.value},pageParams:f,clearDataFn:()=>{},navigate:A=>{}};a(B(c)),t(),a(h({})),s()}else{const c={obj:{id:i,name:o.name,country_id:(x=o.country)==null?void 0:x.value},pageParams:{},clearDataFn:()=>{},navigate:A=>{}};a(G(c)),t(),a(h({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(X,{open:u,onClose:(o,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:[i==null||i==0?"Add ":"Update ",b,e.jsx(E,{onClick:t,children:e.jsx(V,{color:"white"})})]}),e.jsx(N,{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:v(C),children:[e.jsx(U,{name:"country",label:"Country",required:!0,control:g,rules:{required:!0},options:p==null?void 0:p.map(o=>({id:o.id,name:o.name})),loading:j,onChange:o=>{a(_(o))},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:$}),e.jsx(K,{size:{xs:12,md:4},mt:2,children:e.jsx(T,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter State here...",control:g})}),e.jsxs(O,{sx:{p:2},children:[e.jsx(l,{onClick:t,variant:"outlined",color:"secondary",children:"Cancel"}),i==null||i==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};
