import{r as P,j as e,w as p}from"./main-BMMRv56V.js";import{u as T,F as I,C as a}from"./FormPage-BVW5CvFp.js";import{S as h,o as W,c as E,b as l,a as L,d as q}from"./index.esm-BtvPq225.js";import{G as m}from"./GroupCard-BWnQWvHn.js";import{u as w,I as D}from"./useFormPage-DPJesiXn.js";import{c as M}from"./collections.api-DvlronwW.js";import{T as n,F as x,I as j,S as g}from"./TextField-CWEE-Dgp.js";import{M as s}from"./MenuItem-BRyKZl1N.js";import{F as $}from"./FormControlLabel-D9bnwoo8.js";import{S as A}from"./Switch-Cz5xNANc.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";import"./SwitchBase-BoGf5uFH.js";const K=E({title:l().required("Title is required"),slug:l(),description:l(),image_id:q(),image_url:l(),type:l().oneOf(["collection","cookbook","meal_plan","favorites"]).required(),status:l().oneOf(["active","inactive"]),is_public:L(),start_date:l(),end_date:l()}),ae=()=>{const{isEditMode:u,entity:i,isLoading:_,isSaving:b,handleSave:f}=w({basePath:"/collections",allQueryKey:p.collections.all,detailQueryKeyFn:p.collections.detail,apiFns:M,entityName:"Collection"}),{control:r,handleSubmit:v,reset:d,watch:y}=T({resolver:W(K),defaultValues:{title:"",slug:"",description:"",image_id:0,image_url:"",type:"collection",status:"active",is_public:!0,start_date:"",end_date:""}}),C=y("type");P.useEffect(()=>{i?d({title:i.title||"",slug:i.slug||"",description:i.description||"",image_id:i.image_id||0,image_url:i.image_url||"",type:i.type||"collection",status:i.status||"active",is_public:i.is_public??!0,start_date:i.start_date||"",end_date:i.end_date||""}):u||d({title:"",slug:"",description:"",image_id:0,image_url:"",type:"collection",status:"active",is_public:!0,start_date:"",end_date:""})},[i,u,d]);const F=t=>f(t),S=e.jsxs(e.Fragment,{children:[e.jsx(m,{title:"Publish",children:e.jsxs(h,{spacing:2,children:[e.jsx(a,{name:"status",control:r,render:({field:t})=>e.jsxs(x,{fullWidth:!0,children:[e.jsx(j,{children:"Status"}),e.jsxs(g,{...t,label:"Status",children:[e.jsx(s,{value:"active",children:"Active"}),e.jsx(s,{value:"inactive",children:"Inactive"})]})]})}),e.jsx(a,{name:"is_public",control:r,render:({field:t})=>e.jsx($,{control:e.jsx(A,{checked:t.value??!0,onChange:t.onChange}),label:"Public"})})]})}),e.jsx(m,{title:"Image",sx:{mb:0},children:e.jsx(a,{name:"image_id",control:r,render:({field:t})=>e.jsx(a,{name:"image_url",control:r,render:({field:o})=>e.jsx(D,{imageId:t.value||0,imageUrl:o.value||"",onChange:(c,k)=>{t.onChange(c),o.onChange(k)}})})})})]});return e.jsx(I,{backPath:"/collections",onSubmit:v(F),title:u?"Edit Collection":"Add Collection",isLoading:_,isSaving:b,sidebar:S,children:e.jsx(m,{title:"Collection Details",children:e.jsxs(h,{spacing:2.5,children:[e.jsx(a,{name:"title",control:r,render:({field:t,fieldState:o})=>{var c;return e.jsx(n,{...t,label:"Title",required:!0,fullWidth:!0,error:!!o.error,helperText:(c=o.error)==null?void 0:c.message,autoFocus:!0})}}),e.jsx(a,{name:"slug",control:r,render:({field:t})=>e.jsx(n,{...t,label:"Slug",fullWidth:!0,helperText:"Leave blank to auto-generate"})}),e.jsx(a,{name:"description",control:r,render:({field:t})=>e.jsx(n,{...t,label:"Description",fullWidth:!0,multiline:!0,rows:3})}),e.jsx(a,{name:"type",control:r,render:({field:t})=>e.jsxs(x,{fullWidth:!0,children:[e.jsx(j,{children:"Type"}),e.jsxs(g,{...t,label:"Type",children:[e.jsx(s,{value:"collection",children:"Collection"}),e.jsx(s,{value:"cookbook",children:"Cookbook"}),e.jsx(s,{value:"meal_plan",children:"Meal Plan"}),e.jsx(s,{value:"favorites",children:"Favorites"})]})]})}),C==="meal_plan"&&e.jsxs(e.Fragment,{children:[e.jsx(a,{name:"start_date",control:r,render:({field:t})=>e.jsx(n,{...t,label:"Start Date",type:"date",fullWidth:!0,slotProps:{inputLabel:{shrink:!0}}})}),e.jsx(a,{name:"end_date",control:r,render:({field:t})=>e.jsx(n,{...t,label:"End Date",type:"date",fullWidth:!0,slotProps:{inputLabel:{shrink:!0}}})})]})]})})})};export{ae as default};
