import{r as C,j as e,w as c}from"./main-BMMRv56V.js";import{u as F,F as y,C as t}from"./FormPage-BVW5CvFp.js";import{S as p,o as E,c as I,b as a,d as x}from"./index.esm-BtvPq225.js";import{G as u}from"./GroupCard-BWnQWvHn.js";import{u as P,I as W}from"./useFormPage-DPJesiXn.js";import{c as O}from"./cuisines.api-cRv1I8z1.js";import{T as n,F as T,I as k,S as q}from"./TextField-CWEE-Dgp.js";import{M as g}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 w=I({name:a().required("Name is required"),slug:a(),description:a(),image_id:x(),image_url:a(),status:a().oneOf(["active","inactive"]),sort_order:x().integer().min(0),seo_title:a(),seo_description:a()}),U=()=>{const{isEditMode:m,entity:r,isLoading:h,isSaving:j,handleSave:_}=P({basePath:"/cuisines",allQueryKey:c.cuisines.all,detailQueryKeyFn:c.cuisines.detail,apiFns:O,entityName:"Cuisine"}),{control:s,handleSubmit:f,reset:d}=F({resolver:E(w),defaultValues:{name:"",slug:"",description:"",image_id:0,image_url:"",status:"active",sort_order:0,seo_title:"",seo_description:""}});C.useEffect(()=>{r?d({name:r.name||"",slug:r.slug||"",description:r.description||"",image_id:r.image_id||0,image_url:r.image_url||"",status:r.status||"active",sort_order:r.sort_order||0,seo_title:r.seo_title||"",seo_description:r.seo_description||""}):m||d({name:"",slug:"",description:"",image_id:0,image_url:"",status:"active",sort_order:0,seo_title:"",seo_description:""})},[r,m,d]);const b=i=>_(i),v=e.jsxs(e.Fragment,{children:[e.jsxs(u,{title:"Publish",children:[e.jsx(t,{name:"status",control:s,render:({field:i})=>e.jsxs(T,{fullWidth:!0,sx:{mb:2},children:[e.jsx(k,{children:"Status"}),e.jsxs(q,{...i,label:"Status",children:[e.jsx(g,{value:"active",children:"Active"}),e.jsx(g,{value:"inactive",children:"Inactive"})]})]})}),e.jsx(t,{name:"sort_order",control:s,render:({field:i})=>e.jsx(n,{...i,label:"Sort Order",type:"number",fullWidth:!0,slotProps:{htmlInput:{min:0}}})})]}),e.jsx(u,{title:"Image",children:e.jsx(t,{name:"image_id",control:s,render:({field:i})=>e.jsx(t,{name:"image_url",control:s,render:({field:o})=>e.jsx(W,{imageId:i.value||0,imageUrl:o.value||"",onChange:(l,S)=>{i.onChange(l),o.onChange(S)}})})})}),e.jsx(u,{title:"SEO",sx:{mb:0},children:e.jsxs(p,{spacing:2,children:[e.jsx(t,{name:"seo_title",control:s,render:({field:i})=>e.jsx(n,{...i,label:"SEO Title",fullWidth:!0})}),e.jsx(t,{name:"seo_description",control:s,render:({field:i})=>e.jsx(n,{...i,label:"SEO Description",fullWidth:!0,multiline:!0,rows:2})})]})})]});return e.jsx(y,{backPath:"/cuisines",onSubmit:f(b),title:m?"Edit Cuisine":"Add Cuisine",isLoading:h,isSaving:j,sidebar:v,children:e.jsx(u,{title:"Cuisine Details",children:e.jsxs(p,{spacing:2.5,children:[e.jsx(t,{name:"name",control:s,render:({field:i,fieldState:o})=>{var l;return e.jsx(n,{...i,label:"Name",required:!0,fullWidth:!0,error:!!o.error,helperText:(l=o.error)==null?void 0:l.message,autoFocus:!0})}}),e.jsx(t,{name:"slug",control:s,render:({field:i})=>e.jsx(n,{...i,label:"Slug",fullWidth:!0,helperText:"Leave blank to auto-generate from name"})}),e.jsx(t,{name:"description",control:s,render:({field:i})=>e.jsx(n,{...i,label:"Description",fullWidth:!0,multiline:!0,rows:3})})]})})})};export{U as default};
