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-858224db.js";import{c as d,b as y,u as I}from"./index.esm-241dec99.js";import{o as R}from"./yup-9213c3af.js";import"./GenericThumbnailView-2d7b7363.js";import{F as T}from"./FormInput-8eacbbd9.js";import"./componentStyles-107bd37e.js";import"./ScrollableList-bf78e54b.js";import"./TextArea-78cda1eb.js";import{S as U}from"./SelectComponent-e1904bd2.js";import{D as X,a as N}from"./DialogContent-e06a39bc.js";import{D as H}from"./DialogTitle-6e616d34.js";import{D as J}from"./DialogContentText-a2775ca2.js";import{G as K}from"./Grid2-274bb638.js";import{D as O}from"./DialogActions-825c19e9.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};
