1import{r as y,aa as E,j as e}from"./index-9RYYQKcH.js";const _="https://crm-ia-production-c247.up.railway.app/api",k="#F15923",A=()=>"menu-"+Math.random().toString(36).slice(2,8);function v(c,i,j){const b=i+j;if(b<0||b>=c.length)return c;const u=[...c];return[u[i],u[b]]=[u[b],u[i]],u}const f="w-full rounded-lg border border-neutral-300 px-3 py-2 text-sm outline-none focus:border-neutral-900",p="rounded-md border border-neutral-300 bg-white px-2 py-1 text-xs font-semibold text-neutral-600 hover:bg-neutral-100 disabled:opacity-30";function I(){const[c,i]=y.useState(null),[j,b]=y.useState(!1),[u,C]=y.useState(""),[w,S]=y.useState(()=>typeof window<"u"&&localStorage.getItem("chef_pass")||"");y.useEffect(()=>{E().then(i)},[]);const m=(a,t)=>i(r=>r.map((n,s)=>s===a?{...n,...t}:n)),h=(a,t)=>m(a,{sections:t(c[a].sections||[])}),N=(a,t,r)=>h(a,n=>n.map((s,l)=>l===t?{...s,items:r(s.items||[])}:s)),M=async()=>{if(c){b(!0),C(""),localStorage.setItem("chef_pass",w);try{const a=await fetch(`${_}/chef-menus`,{method:"PUT",headers:{"Content-Type":"application/json","x-chef-pass":w},body:JSON.stringify({menus:c})});if(a.status===401)C("â Contraseña incorrecta.");else if(a.ok)C("â
Guardado â ya se refleja en la página del cliente y en el contrato.");else throw new Error}catch{C("â Error al guardar, intenta de nuevo.")}b(!1)}};return c?e.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-8",children:[e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("a",{href:"/admin/chef",className:"mb-2 inline-flex items-center gap-1.5 rounded-lg border border-neutral-300 bg-white px-3 py-1.5 text-sm font-semibold text-neutral-700 hover:bg-neutral-100",children:"â Panel del chef"}),e.jsx("h1",{className:"text-2xl font-bold text-neutral-900",children:"Editor de menús · Chef"}),e.jsx("p",{className:"text-sm text-neutral-500",children:"Edita los menús. Al guardar, se actualiza solo en el link del cliente y en el contrato."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"password",value:w,onChange:a=>S(a.target.value),placeholder:"Contraseña admin",className:"rounded-lg border border-neutral-300 px-3 py-2 text-sm"}),e.jsx("button",{onClick:M,disabled:j,className:"rounded-lg px-5 py-2 text-sm font-bold text-white disabled:opacity-50",style:{background:k},children:j?"Guardandoâ¦":"Guardar cambios"})]})]}),u&&e.jsx("div",{className:"mb-4 rounded-lg bg-neutral-100 px-4 py-2 text-sm",children:u}),e.jsx("div",{className:"space-y-6",children:c.map((a,t)=>e.jsxs("div",{className:"rounded-2xl border border-neutral-200 bg-white p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("input",{value:a.name,onChange:r=>m(t,{name:r.target.value}),className:`${f} text-base font-bold`}),e.jsx("button",{className:p,disabled:t===0,onClick:()=>i(r=>v(r,t,-1)),children:"â"}),e.jsx("button",{className:p,disabled:t===c.length-1,onClick:()=>i(r=>v(r,t,1)),children:"â"}),e.jsx("button",{className:"rounded-md border border-red-200 bg-red-50 px-2 py-1 text-xs font-semibold text-red-600 hover:bg-red-100",onClick:()=>{confirm(`¿Borrar el menú "${a.name}"?`)&&i(r=>r.filter((n,s)=>s!==t))},children:"Borrar menú"})]}),e.jsx("input",{value:a.note||"",onChange:r=>m(t,{note:r.target.value}),placeholder:"Nota del menú (opcional)",className:`${f} mb-3 text-xs`}),a.setMenus?e.jsxs("div",{className:"space-y-3",children:[e.jsx("textarea",{value:a.setNote||"",onChange:r=>m(t,{setNote:r.target.value}),placeholder:"Nota (ej. incluye jugo y café)",rows:2,className:`${f} text-xs`}),a.setMenus.map((r,n)=>e.jsxs("div",{className:"rounded-lg border border-neutral-200 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("input",{value:r.name,onChange:s=>m(t,{setMenus:a.setMenus.map((l,o)=>o===n?{...l,name:s.target.value}:l)}),className:`${f} font-semibold`}),e.jsx("button",{className:"rounded-md border border-red-200 bg-red-50 px-2 py-1 text-xs text-red-600",onClick:()=>m(t,{setMenus:a.setMenus.filter((s,l)=>l!==n)}),children:"Ã"})]}),r.items.map((s,l)=>e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("input",{value:s,onChange:o=>m(t,{setMenus:a.setMenus.map((d,x)=>x===n?{...d,items:d.items.map((g,$)=>$===l?o.target.value:g)}:d)}),className:`${f} text-sm`}),e.jsx("button",{className:p,onClick:()=>m(t,{setMenus:a.setMenus.map((o,d)=>d===n?{...o,items:o.items.filter((x,g)=>g!==l)}:o)}),children:"Ã"})]},l)),e.jsx("button",{className:"mt-1 text-xs font-semibold text-neutral-500",onClick:()=>m(t,{setMenus:a.setMenus.map((s,l)=>l===n?{...s,items:[...s.items,""]}:s)}),children:"+ plato"})]},n)),e.jsx("button",{className:"text-sm font-semibold",style:{color:k},onClick:()=>m(t,{setMenus:[...a.setMenus,{name:`Menu ${a.setMenus.length+1}`,items:[""]}]}),children:"+ agregar menú armado"})]}):e.jsxs("div",{className:"space-y-3",children:[(a.sections||[]).map((r,n)=>e.jsxs("div",{className:"rounded-lg border border-neutral-200 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("input",{value:r.name,onChange:s=>h(t,l=>l.map((o,d)=>d===n?{...o,name:s.target.value}:o)),className:`${f} font-semibold`,placeholder:"Sección (ej. Appetizers)"}),e.jsx("input",{type:"number",value:r.pick??"",onChange:s=>h(t,l=>l.map((o,d)=>d===n?{...o,pick:s.target.value===""?void 0:Number(s.target.value)}:o)),className:"w-20 rounded-lg border border-neutral-300 px-2 py-2 text-sm",placeholder:"pick",title:"Cantidad exacta a elegir (opcional)"}),e.jsx("button",{className:p,disabled:n===0,onClick:()=>h(t,s=>v(s,n,-1)),children:"â"}),e.jsx("button",{className:p,disabled:n===(a.sections||[]).length-1,onClick:()=>h(t,s=>v(s,n,1)),children:"â"}),e.jsx("button",{className:"rounded-md border border-red-200 bg-red-50 px-2 py-1 text-xs text-red-600",onClick:()=>h(t,s=>s.filter((l,o)=>o!==n)),children:"Ã"})]}),(r.items||[]).map((s,l)=>e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("input",{value:s.name,onChange:o=>N(t,n,d=>d.map((x,g)=>g===l?{...x,name:o.target.value}:x)),className:`${f} text-sm`,placeholder:"Nombre del plato"}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1 text-xs text-neutral-500",title:"Vegetariano",children:[e.jsx("input",{type:"checkbox",checked:!!s.veg,onCh
1ange:o=>N(t,n,d=>d.map((x,g)=>g===l?{...x,veg:o.target.checked||void 0}:x))})," ð±"]}),e.jsx("button",{className:p,disabled:l===0,onClick:()=>N(t,n,o=>v(o,l,-1)),children:"â"}),e.jsx("button",{className:p,disabled:l===(r.items||[]).length-1,onClick:()=>N(t,n,o=>v(o,l,1)),children:"â"}),e.jsx("button",{className:p,onClick:()=>N(t,n,o=>o.filter((d,x)=>x!==l)),children:"Ã"})]},l)),e.jsx("button",{className:"mt-1 text-xs font-semibold text-neutral-500",onClick:()=>N(t,n,s=>[...s,{name:""}]),children:"+ plato"})]},n)),e.jsx("button",{className:"text-sm font-semibold",style:{color:k},onClick:()=>h(t,r=>[...r,{name:"",items:[]}]),children:"+ agregar sección"})]})]},a.id))}),e.jsx("button",{className:"mt-6 w-full rounded-2xl border-2 border-dashed border-neutral-300 py-4 text-sm font-bold text-neutral-500 hover:border-neutral-500",onClick:()=>i(a=>[...a,{id:A(),name:"Nuevo menú",sections:[{name:"",items:[]}]}]),children:"+ Agregar menú nuevo"}),e.jsxs("div",{className:"sticky bottom-4 mt-6",children:[e.jsx("button",{onClick:M,disabled:j,className:"w-full rounded-xl py-3 text-base font-bold text-white shadow-lg disabled:opacity-50",style:{background:k},children:j?"Guardandoâ¦":"Guardar cambios"}),u&&e.jsx("div",{className:"mt-2 rounded-lg bg-neutral-100 px-4 py-2 text-center text-sm",children:u})]})]}):e.jsx("div",{className:"flex min-h-screen items-center justify-center text-neutral-400",children:"Cargando menúsâ¦"})}export{I as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.