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 _,fZ as $,z as c,o7 as B,lO as h,o8 as G}from"./index-d895656a.js";import{c as d,b as y,u as T}from"./index.esm-1087b2f3.js";import{o as U}from"./yup-9573aa79.js";import"./GenericThumbnailView-532ea2d7.js";import{F as I}from"./FormInput-9b5da280.js";import"./componentStyles-866300fe.js";import"./ScrollableList-e2b22048.js";import"./TextArea-fb0d0821.js";import{S as N}from"./SelectComponent-32c91e44.js";import{D as O,a as R}from"./DialogContent-4ce43512.js";import{D as X}from"./DialogTitle-738ca272.js";import{D as Z}from"./DialogContentText-8b9b0e0c.js";import{G as H}from"./Grid2-5bd460ea.js";import{D as J}from"./DialogActions-7b82f6f6.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:Y,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(Z,{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};
