import{d as L,a as q,b as A,aM as w,o5 as k,r as z,j as e,I as E,ax as V,o6 as _,fY as $,z as c,o7 as B,lO as h,o8 as G}from"./index-c5c88b67.js";import{c as d,b as y,u as T}from"./index.esm-81620445.js";import{o as U}from"./yup-41605283.js";import"./GenericThumbnailView-43782201.js";import{F as I}from"./FormInput-86f14880.js";import"./componentStyles-a5e5a830.js";import"./ScrollableList-21ab2b9c.js";import"./TextArea-aad9dffe.js";import{S as N}from"./SelectComponent-8c888daa.js";import{D as O,a as R}from"./DialogContent-1350b249.js";import{D as X}from"./DialogTitle-da236dcc.js";import{D as Y}from"./DialogContentText-659ecbc3.js";import{G as H}from"./Grid2-0ff60c92.js";import{D as J}from"./DialogActions-1232a7fa.js";const Sr=({modal:u,closeModal:t,mastersName:b,edit_Id:i,mastersValue:K})=>{const a=L(),{state:{selectedData:r,pageParams:f},mini:{miniStatesList:M,miniCountryParams:n,miniCountriesList:p,miniCountryLoading:j,miniCityList:Q,miniItemgroupParams:W,miniStatesParams:Z,miniStateLoading:D,miniCityParams:rr,miniCityLoading:er,miniItemgroupList:or,miniItemgroupLoading:ir,countryValue:nr,stateValue:tr},system:{userAccessList:ar}}=q(o=>({system:A(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}=T({resolver:U(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 l={obj:{name:o.name,country_id:(m=o.country)==null?void 0:m.value},pageParams:f,clearDataFn:()=>{},navigate:F=>{}};a(B(l)),t(),a(h({})),s()}else{const l={obj:{id:i,name:o.name,country_id:(x=o.country)==null?void 0:x.value},pageParams:{},clearDataFn:()=>{},navigate:F=>{}};a(G(l)),t(),a(h({})),s()}};return e.jsx(e.Fragment,{children:e.jsxs(O,{open:u,onClose:(o,m)=>{m!=="backdropClick"&&t()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(X,{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(R,{sx:{px:"24px",pt:"12px !important",pb:0},children:e.jsx(Y,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:v(C),children:[e.jsx(N,{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(H,{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(J,{sx:{p:2},children:[e.jsx(c,{onClick:t,variant:"outlined",color:"secondary",children:"Cancel"}),i==null||i==0?e.jsx(c,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):e.jsx(c,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})})]})})};export{Sr as A};
