import{b as B,r as E,a as V,g as W,eu as R,v4 as U,j as e,B as s,P as g,iv as Z,J as t,vZ as I,v_ as b,vm as _,v$ as J}from"./index-d2b25495.js";import{c as A,b as h}from"./index.esm-3043d6d4.js";import{o as M}from"./yup-267e586f.js";import{u as T}from"./index.esm-ce3c2c20.js";import"./componentStyles-0e851d91.js";import{F as H}from"./FormInput-d202e905.js";/* empty css                   */import"./ScrollableList-fc1de312.js";import{S as K}from"./SelectComponent-d286bfef.js";import{D as S,a as z}from"./DialogContent-cded694d.js";import{D as P}from"./DialogTitle-a145b392.js";import{D as L}from"./DialogActions-7c802cc8.js";const ve=({modal:F,closeModal:m,mastersName:G,editId:o,mastersValue:N,groupdata:O})=>{const i=B(),[$,p]=E.useState(!1),{mini:{miniStatesList:Q,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}}=V(n=>({system:W(n),mini:R(n),itemgroup:U(n)})),w=A().shape({name:h().required("Please enter your group name").trim().matches(/^[a-zA-Z0-9 ]*$/,"group name should not contain special characters"),parent:A().shape({label:h().optional(),value:h().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)},q=()=>{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(J({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(P,{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(g,{container:!0,spacing:3,children:[e.jsx(g,{size:{xs:12,md:4},children:e.jsx(H,{name:"name",label:"Group name",required:!0,type:"text",placeholder:"Enter Group here...",control:d})}),e.jsx(g,{size:{xs:12,md:4},children:e.jsx(K,{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:Z})})]})})})})}),e.jsxs(L,{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:$,onClose:C,children:[e.jsx(P,{children:"Confirm Close"}),e.jsx(z,{children:"⚠️ Are you sure you want to close? Any unsaved changes will be lost."}),e.jsxs(L,{children:[e.jsx(t,{onClick:C,color:"primary",children:"Cancel"}),e.jsx(t,{onClick:q,color:"error",variant:"contained",children:"Close"})]})]})]})};export{ve as A};
