import type { Category, Dish } from '../utils/store' // Ajout d'un plat depuis le dashboard export default defineEventHandler(async (event) => { const body = await readBody<{ name?: string, desc?: string, cat?: Category, priceL?: number | null, priceXL?: number | null, meats?: string[] }>(event) if (!body?.name?.trim()) throw createError({ statusCode: 400, statusMessage: 'Nom obligatoire' }) const prices: Dish['prices'] = {} if (body.priceL != null) prices.L = body.priceL if (body.priceXL != null) prices.XL = body.priceXL if (!Object.keys(prices).length) prices.XL = null const dish: Dish = { id: body.name.toLowerCase().normalize('NFD').replace(/[^a-z0-9]+/g, '-') + '-' + Date.now().toString(36), name: body.name.trim(), desc: body.desc?.trim() || '', cat: body.cat || 'wok', prices, meats: body.meats || [], available: true } db.dishes.push(dish) return dish })