import{b as W,r as q,a as B,h as E,ez as Q,v4 as R,j as e,B as s,Q as h,iQ as U,K as t,vV as I,vW as b,vm as _,vX as K}from"./index-60a3c753.js";import{c as A,b as g}from"./index.esm-62d6b2f7.js";import{o as M}from"./yup-92678dde.js";import{u as T}from"./index.esm-c494934a.js";import"./componentStyles-7753bbb9.js";import{F as X}from"./FormInput-74e2c4d2.js";/* empty css                   */import"./ScrollableList-1962b023.js";import{S as Z}from"./SelectComponent-e431868e.js";import{D as S,a as z}from"./DialogContent-89e21f2e.js";import{D as L}from"./DialogTitle-fe69da5c.js";import{D as P}from"./DialogActions-e754942c.js";const ve=({modal:F,closeModal:m,mastersName:G,editId:o,mastersValue:H,groupdata:J})=>{const i=W(),[k,p]=q.useState(!1),{mini:{miniStatesList:N,miniCountryParams:O,miniCountriesList:Y,miniCountryLoading:D,miniCityList:ee,miniItemgroupParams:a,miniStatesParams:re,miniStateLoading:ne,miniCityParams:oe,miniCityLoading:ie,miniItemgroupList:l,miniItemgroupLoading:$,countryValue:ae,stateValue:se},itemgroup:{selectedData:r},system:{userAccessList:te}}=B(n=>({system:E(n),mini:Q(n),itemgroup:R(n)})),w=A().shape({name:g().required("Please enter your group name").trim().matches(/^[a-zA-Z0-9 ]*$/,"group name should not contain special characters"),parent:A().shape({label:g().optional(),value:g().optional()}).optional().nullable()}),{control:d,handleSubmit:x,reset:c}=T({resolver:M(w),values:{name:r!=null&&r.name?r==null?void 0:r.name:"",parent:r!=null&&r.parent?{label:r!=null&&r.parent?`${r==null?void 0:r.parent.name}`:"",value:r!=null&&r.parent?`${r==null?void 0:r.parent.id}`:""}:null}}),j=()=>{p(!0)},V=()=>{p(!1),m(),c()},C=()=>{p(!1)},f=n=>{var y,v;if(o==null||o==0){const u={name:n.name,parent_id:(y=n.parent)==null?void 0:y.value,product_type:1};i(I({obj:u})),i(b({search:"",page:1,page_size:10})),i(_({page:1,page_size:10})),m(),c()}else{const u={id:o,name:n.name,parent_id:(v=n.parent)==null?void 0:v.value,product_type:1};i(K({obj:u,pageParams:{},clearDataFn:()=>{},navigate:me=>{}})),i(_({page:1,page_size:10})),i(b({search:"",page:1,page_size:10})),m(),c()}};return e.jsxs(e.Fragment,{children:[e.jsxs(S,{open:F,onClose:j,maxWidth:"md",fullWidth:!0,children:[e.jsxs(L,{children:[o==null||o==0?"Add ":"Update ",G]}),e.jsx(s,{sx:{border:"1px solid #ccc",padding:1,borderRadius:1,bgcolor:"#f9f9f9"},children:e.jsx(z,{children:e.jsx(s,{mt:1,children:e.jsx("form",{action:"",children:e.jsxs(h,{container:!0,spacing:3,children:[e.jsx(h,{size:{xs:12,md:4},children:e.jsx(X,{name:"name",label:"Group name",required:!0,type:"text",placeholder:"Enter Group here...",control:d})}),e.jsx(h,{size:{xs:12,md:4},children:e.jsx(Z,{name:"parent",label:"Parent Group",control:d,rules:{required:!0},options:l==null?void 0:l.map(n=>({id:n.id,name:n.name})),loading:$,selectParams:{page:a.page,page_size:a.page_size,search:a.search,no_of_pages:a.no_of_pages},hasMore:a.page<a.no_of_pages,fetchapi:U})})]})})})})}),e.jsxs(P,{children:[e.jsx(s,{textAlign:"center",children:e.jsx(t,{onClick:j,variant:"outlined",color:"secondary",children:"Cancel"})}),o==null||o==0?e.jsx(s,{textAlign:"right",children:e.jsx(t,{color:"primary",type:"submit",onClick:x(f),variant:"contained",size:"large",children:"Submit"})}):e.jsx(s,{textAlign:"right",children:e.jsx(t,{variant:"contained",type:"submit",onClick:x(f),color:"primary",autoFocus:!0,children:"Update"})})]})]}),e.jsxs(S,{open:k,onClose:C,children:[e.jsx(L,{children:"Confirm Close"}),e.jsx(z,{children:"⚠️ Are you sure you want to close? Any unsaved changes will be lost."}),e.jsxs(P,{children:[e.jsx(t,{onClick:C,color:"primary",children:"Cancel"}),e.jsx(t,{onClick:V,color:"error",variant:"contained",children:"Close"})]})]})]})};export{ve as A};
