// Online ordering settings (plan phase 3S, steps S.4 and S.6): which services the online
// ordering app offers (takeaway, delivery), when (ordering hours per day, or any time), how
// long before an order can be ready (preparation), the times offered (every N minutes, days
// ahead) and "as soon as possible"; and table bookings (a table only, or with food ordered
// ahead): their own hours, time grid, notice, days ahead, party size, and when the kitchen gets
// the food before the guests arrive. The cloud enforces them. PUT /api/connect/fees/ordering.
import { useState } from 'react'
import toast from 'react-hot-toast'
import { Plus, X } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Field, IconButton, Input, Select, Switch } from '@xenia/ui'
import client from '../../api/client'
import { DAYS, orderingBody, orderingToForm } from './feesLogic'
export default function OrderingSettings({ ordering, onSaved }) {
const { t } = useTranslation('manager')
const [form, setForm] = useState(() => orderingToForm(ordering))
const [busy, setBusy] = useState(false)
const set = (k, v) => setForm(f => ({ ...f, [k]: v }))
const setRes = (k, v) => setForm(f => ({ ...f, res: { ...f.res, [k]: v } }))
const toggleService = s => set('services', form.services.includes(s) ? form.services.filter(x => x !== s) : ['takeaway', 'delivery'].filter(x => x === s || form.services.includes(x)))
const save = async () => {
setBusy(true)
try {
const { data } = await client.put('/api/connect/fees/ordering', orderingBody(form))
setForm(orderingToForm(data))
toast.success(t('fees.saved'))
onSaved?.()
} catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
return (