import{n as q,r as O,j as e,w as g}from"./main-BMMRv56V.js";import{u as T,F as k,C as a}from"./FormPage-BVW5CvFp.js";import{S as _,o as K,c as L,b as o,d as x}from"./index.esm-BtvPq225.js";import{G as d}from"./GroupCard-BWnQWvHn.js";import{u as N,I as w}from"./useFormPage-DPJesiXn.js";import{c as j}from"./categories.api-hgkmpP-X.js";import{T as n,F as f,I as b,S as v}from"./TextField-CWEE-Dgp.js";import{M as u}from"./MenuItem-BRyKZl1N.js";import"./ArrowBack-wNhJWsVJ.js";import"./Save-cfs8JpKk.js";import"./Grid-DyVgKpIU.js";import"./isMuiElement-CEQVLtSO.js";import"./Close-Bxz3dk_v.js";import"./useMutation-CKlbob41.js";import"./listItemTextClasses-CLRRC5Y4.js";const A=L({name:o().required("Name is required"),slug:o(),description:o(),image_id:x(),image_url:o(),parent_id:x(),status:o().oneOf(["active","inactive"]),sort_order:x().integer().min(0),seo_title:o(),seo_description:o()}),ee=()=>{var h;const{isEditMode:m,entity:t,isLoading:y,isSaving:S,handleSave:C}=N({basePath:"/categories",allQueryKey:g.categories.all,detailQueryKeyFn:g.categories.detail,apiFns:j,entityName:"Category"}),{data:c}=q({queryKey:g.categories.list({per_page:100}),queryFn:()=>j.getList({per_page:100})}),F=((h=c==null?void 0:c.data)==null?void 0:h.items)??[],{control:i,handleSubmit:P,reset:p}=T({resolver:K(A),defaultValues:{name:"",slug:"",description:"",image_id:0,image_url:"",parent_id:0,status:"active",sort_order:0,seo_title:"",seo_description:""}});O.useEffect(()=>{t?p({name:t.name||"",slug:t.slug||"",description:t.description||"",image_id:t.image_id||0,image_url:t.image_url||"",parent_id:t.parent_id||0,status:t.status||"active",sort_order:t.sort_order||0,seo_title:t.seo_title||"",seo_description:t.seo_description||""}):m||p({name:"",slug:"",description:"",image_id:0,image_url:"",parent_id:0,status:"active",sort_order:0,seo_title:"",seo_description:""})},[t,m,p]);const E=r=>C(r),I=e.jsxs(e.Fragment,{children:[e.jsxs(d,{title:"Publish",children:[e.jsx(a,{name:"status",control:i,render:({field:r})=>e.jsxs(f,{fullWidth:!0,sx:{mb:2},children:[e.jsx(b,{children:"Status"}),e.jsxs(v,{...r,label:"Status",children:[e.jsx(u,{value:"active",children:"Active"}),e.jsx(u,{value:"inactive",children:"Inactive"})]})]})}),e.jsx(a,{name:"sort_order",control:i,render:({field:r})=>e.jsx(n,{...r,label:"Sort Order",type:"number",fullWidth:!0,slotProps:{htmlInput:{min:0}}})})]}),e.jsx(d,{title:"Image",children:e.jsx(a,{name:"image_id",control:i,render:({field:r})=>e.jsx(a,{name:"image_url",control:i,render:({field:s})=>e.jsx(w,{imageId:r.value||0,imageUrl:s.value||"",onChange:(l,W)=>{r.onChange(l),s.onChange(W)}})})})}),e.jsx(d,{title:"SEO",sx:{mb:0},children:e.jsxs(_,{spacing:2,children:[e.jsx(a,{name:"seo_title",control:i,render:({field:r})=>e.jsx(n,{...r,label:"SEO Title",fullWidth:!0})}),e.jsx(a,{name:"seo_description",control:i,render:({field:r})=>e.jsx(n,{...r,label:"SEO Description",fullWidth:!0,multiline:!0,rows:2})})]})})]});return e.jsx(k,{backPath:"/categories",onSubmit:P(E),title:m?"Edit Category":"Add Category",isLoading:y,isSaving:S,sidebar:I,children:e.jsx(d,{title:"Category Details",children:e.jsxs(_,{spacing:2.5,children:[e.jsx(a,{name:"name",control:i,render:({field:r,fieldState:s})=>{var l;return e.jsx(n,{...r,label:"Name",required:!0,fullWidth:!0,error:!!s.error,helperText:(l=s.error)==null?void 0:l.message,autoFocus:!0})}}),e.jsx(a,{name:"slug",control:i,render:({field:r})=>e.jsx(n,{...r,label:"Slug",fullWidth:!0,helperText:"Leave blank to auto-generate from name"})}),e.jsx(a,{name:"description",control:i,render:({field:r})=>e.jsx(n,{...r,label:"Description",fullWidth:!0,multiline:!0,rows:3})}),e.jsx(a,{name:"parent_id",control:i,render:({field:r})=>e.jsxs(f,{fullWidth:!0,children:[e.jsx(b,{children:"Parent Category"}),e.jsxs(v,{...r,label:"Parent Category",value:r.value||0,children:[e.jsx(u,{value:0,children:"None"}),F.filter(s=>s.id!==(t==null?void 0:t.id)).map(s=>e.jsx(u,{value:s.id,children:s.name},s.id))]})]})})]})})})};export{ee as default};
