import{b as q,r as B,a as R,h as V,er as W,u$ as Q,j as e,B as s,Q as h,iE as U,K as t,vQ as I,vR as b,vh as _,vS as K}from"./index-76d4793e.js";import{c as S,b as g}from"./index.esm-ad8a7c9f.js";import{o as M}from"./yup-688ec4f6.js";import{u as T}from"./index.esm-3adfd9f7.js";import"./componentStyles-0803b39e.js";import{F as Z}from"./FormInput-8f40ded1.js";/* empty css                   */import"./ScrollableList-4dae3697.js";import{S as H}from"./SelectComponent-3c1140e6.js";import{D as A,a as z}from"./DialogContent-7bd8dd8f.js";import{D as L}from"./DialogTitle-71dd5b3a.js";import{D as P}from"./DialogActions-5a5e1db9.js";const ve=({modal:F,closeModal:m,mastersName:G,editId:o,mastersValue:J,groupdata:N})=>{const i=q(),[$,p]=B.useState(!1),{mini:{miniStatesList:O,miniCountryParams:X,miniCountriesList:Y,miniCountryLoading:D,miniCityList:ee,miniItemgroupParams:a,miniStatesParams:re,miniStateLoading:ne,miniCityParams:oe,miniCityLoading:ie,miniItemgroupList:l,miniItemgroupLoading:k,countryValue:ae,stateValue:se},itemgroup:{selectedData:r},system:{userAccessList:te}}=R(n=>({system:V(n),mini:W(n),itemgroup:Q(n)})),w=S().shape({name:g().required("Please enter your group name").trim().matches(/^[a-zA-Z0-9 ]*$/,"group name should not contain special characters"),parent:S().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)},E=()=>{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(A,{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(Z,{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(H,{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:k,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(A,{open:$,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:E,color:"error",variant:"contained",children:"Close"})]})]})]})};export{ve as A};
