import{b as k,a as z,h as P,ez as L,xu as F,j as e,B as o,Q as p,xv as G,K as h,xw as q,xm as A,xx as $}from"./index-60a3c753.js";import{c as b,b as c}from"./index.esm-62d6b2f7.js";import{o as W}from"./yup-92678dde.js";import{u as B}from"./index.esm-c494934a.js";import"./componentStyles-7753bbb9.js";import{F as R}from"./FormInput-74e2c4d2.js";/* empty css                   */import"./ScrollableList-1962b023.js";import{T}from"./TextArea-b2d5bcf9.js";import{S as V}from"./SelectComponent-e431868e.js";import{D as w,a as E}from"./DialogContent-89e21f2e.js";import{D as U}from"./DialogTitle-fe69da5c.js";import{D as K}from"./DialogActions-e754942c.js";const jr=({modal:v,closeModal:s,mastersName:C,editId:n,mastersValue:Q,groupdata:Z})=>{const t=k(),{mini:{miniStatesList:H,miniCountryParams:J,miniCountriesList:M,miniCountryLoading:N,miniCityList:O,miniAccountgroupParams:a,miniStatesParams:X,miniStateLoading:Y,miniCityParams:D,miniCityLoading:I,miniAccountgroupList:u,miniAccountgroupLoading:_,countryValue:rr,stateValue:er},accountgroup:{selectedData:r,pageParams:m},system:{userAccessList:ir}}=z(i=>({system:P(i),mini:L(i),accountgroup:F(i)})),S=b().shape({name:c().required("Please enter your group name").trim().matches(/^[a-zA-Z0-9 ]*$/,"group name should not contain special characters"),parent:b().shape({label:c().optional(),value:c().optional()}).optional().nullable(),remarks:c().required("Please enter description").trim()}),{control:l,handleSubmit:x,reset:d}=B({resolver:W(S),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,remarks:r!=null&&r.remarks?r==null?void 0:r.remarks:""}}),j=i=>{var f,y;if(n==null||n==0){const g={name:i.name,parent_id:(f=i.parent)==null?void 0:f.value,product_type:1,remarks:i.remarks};t(q({obj:g,params:m,clearDataFn:()=>{t(A({...m,search:"",page:1,page_size:10})),s(),d()}}))}else{const g={id:n,name:i.name,parent_id:(y=i.parent)==null?void 0:y.value,product_type:1,remarks:i.remarks};t($({obj:g,params:m,clearDataFn:()=>{t(A({...m,search:"",page:1,page_size:10})),s(),d()},navigate:nr=>{}}))}};return e.jsx(e.Fragment,{children:e.jsxs(w,{open:v,onClose:s,maxWidth:"md",fullWidth:!0,children:[e.jsxs(U,{children:[n==null||n==0?"Add ":"Update ",C]}),e.jsx(o,{sx:{border:"1px solid #ccc",padding:1,borderRadius:1,bgcolor:"#f9f9f9"},children:e.jsx(E,{children:e.jsx(o,{mt:1,children:e.jsxs("form",{action:"",children:[e.jsxs(p,{container:!0,spacing:3,children:[e.jsx(p,{size:{xs:12,md:4},children:e.jsx(R,{name:"name",label:"Group name",required:!0,type:"text",placeholder:"Enter Group here...",control:l})}),e.jsx(p,{size:{xs:12,md:4},children:e.jsx(V,{name:"parent",label:"Parent Group",control:l,rules:{required:!0},options:u==null?void 0:u.map(i=>({id:i.id,name:i.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:G})})]}),e.jsx(p,{size:{xs:12},mt:2,children:e.jsx(T,{name:"remarks",required:!0,label:"Description",type:"text",placeholder:"Write Description here...",minRows:4,containerSx:{display:"grid",gap:1},control:l})})]})})})}),e.jsxs(K,{children:[e.jsx(o,{textAlign:"center",children:e.jsx(h,{onClick:s,variant:"outlined",color:"secondary",children:"Cancel"})}),n==null||n==0?e.jsx(o,{textAlign:"right",children:e.jsx(h,{color:"primary",type:"submit",onClick:x(j),variant:"contained",size:"large",children:"Submit"})}):e.jsx(o,{textAlign:"right",children:e.jsx(h,{variant:"contained",type:"submit",onClick:x(j),color:"primary",autoFocus:!0,children:"Update"})})]})]})})};export{jr as A};
