import{c as e,f as s,d as r}from"./router.chunk.YsRm4bSN.js";import{_ as __}from"./wordpress.chunk.BVds2GcU.js";import{aL as a,w as t,bj as i,aw as u,ax as o}from"./main.chunk.N-eZ2ybB.js";import{d as n,g as c,n as l,f as d,e as y}from"./forms.chunk.Bz8aaTWe.js";const g=n({id:c.string(),name:d(),slug:d().nullish(),image:a.nullish(),description:d().nullish(),parent_id:d().nullish(),level:l(),count:l(),is_default:c.boolean().default(!1)}),m=g.omit({id:!0,level:!0,count:!0,is_default:!0}),C=g,p=(e,s)=>{const r=y(s).safeParse(e);if(!r.success)throw console.error(r.error.errors),t.error("Invalid Data Structure",{description:"There is a mismatch in the data structure. Please try again later or contact support."}),new Error(r.error.errors.map(e=>e.message).join(", "));return e},f=()=>u.get(o.TOP_LEVEL_CATEGORIES).then(e=>p(e.data,C)),h=()=>e({queryKey:["TopLevelCategories"],queryFn:f}),q=s=>e({queryKey:["SubCategories",s],enabled:!!Number(s),queryFn:()=>(i(s,"Parent ID is required"),(e=>u.get(o.SUBCATEGORIES(e)).then(e=>p(e.data,C)))(s))}),v=()=>u.get(o.CATEGORIES).then(e=>p(e.data,C)),S=()=>e({queryKey:["Categories"],queryFn:v}),E=e=>u.post(o.CATEGORIES,e),T=()=>{const e=s();return r({mutationFn:E,onSuccess(){e.invalidateQueries({queryKey:["Categories"]}),e.invalidateQueries({queryKey:["TopLevelCategories"]}),e.invalidateQueries({queryKey:["SubCategories"]}),t.success(__("Category created successfully","growfund"))}})},K=({id:e,...s})=>u.put(o.CATEGORIES_WITH_ID(e),s),I=()=>{const e=s();return r({mutationFn:K,onSuccess(){e.invalidateQueries({queryKey:["Categories"]}),e.invalidateQueries({queryKey:["TopLevelCategories"]}),e.invalidateQueries({queryKey:["SubCategories"]}),t.success(__("Category updated successfully","growfund"))}})},_=e=>u.patch(o.CATEGORIES_BULK_ACTIONS,e),b=()=>{const e=s();return r({mutationFn:_,onSuccess(s){e.invalidateQueries({queryKey:["Categories"]}),e.invalidateQueries({queryKey:["TopLevelCategories"]}),e.invalidateQueries({queryKey:["SubCategories"]}),t.success(s.message)}})};export{m as C,q as a,T as b,I as c,S as d,b as e,h as u};
