import { useState } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { Plus, Percent, Power, Pencil, Trash2, Star, Layers, GripVertical, ChevronDown, ChevronUp, X, Info, } from 'lucide-react' import toast from 'react-hot-toast' import client from '../../../api/client' import Button from '../../../ui/Button' import Modal from '../../../ui/Modal' import { ConfirmModal } from '../../../ui/Modal' // ─── API ───────────────────────────────────────────────────────────────────── const api = { list: (params) => client.get('/api/pricing/modifiers', { params }).then(r => r.data), create: body => client.post('/api/pricing/modifiers', body).then(r => r.data), update: (id, b) => client.put(`/api/pricing/modifiers/${id}`, b).then(r => r.data), toggle: id => client.patch(`/api/pricing/modifiers/${id}/toggle`).then(r => r.data), reorder: items => client.patch('/api/pricing/modifiers/reorder', { items }), remove: id => client.delete(`/api/pricing/modifiers/${id}`), groups: () => client.get('/api/pricing/groups').then(r => r.data), products: () => client.get('/api/products', { params: { all: true } }).then(r => r.data), categories: () => client.get('/api/products/categories').then(r => r.data), prepZones: () => client.get('/api/prep-zones').then(r => r.data), } // ─── Constants ─────────────────────────────────────────────────────────────── const COLORS = [ '#6366f1','#8b5cf6','#ec4899','#f43f5e','#f97316', '#eab308','#22c55e','#14b8a6','#0ea5e9','#64748b', ] const CONDITION_TYPES = [ { value: 'time_range', label: 'Ώρα ημέρας (εύρος)' }, { value: 'date_range', label: 'Εύρος ημερομηνιών' }, { value: 'specific_date', label: 'Συγκεκριμένη ημερομηνία' }, { value: 'day_of_week', label: 'Ημέρα εβδομάδας' }, { value: 'min_item_quantity', label: 'Ελάχιστη ποσότητα προϊόντος' }, { value: 'min_category_qty', label: 'Ελάχιστη ποσότητα κατηγορίας' }, { value: 'min_order_value', label: 'Ελάχιστη αξία παραγγελίας' }, { value: 'order_channel', label: 'Κανάλι παραγγελίας' }, { value: 'price_group_active', label: 'Ομάδα τιμής ενεργή' }, { value: 'user_tier', label: 'Επίπεδο πελάτη (placeholder)' }, { value: 'low_stock', label: 'Χαμηλό απόθεμα (placeholder)' }, ] const DAYS = ['Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο','Κυριακή'] const CHANNELS = ['pos','online','qr','takeaway'] const ROUND_OPTIONS = [ { value: '', label: 'Χωρίς στρογγυλοποίηση' }, { value: '0.05', label: 'Στο κοντινότερο €0,05' }, { value: '0.10', label: 'Στο κοντινότερο €0,10' }, { value: '0.20', label: 'Στο κοντινότερο €0,20' }, { value: '0.50', label: 'Στο κοντινότερο €0,50' }, { value: 'x.99', label: 'Σε x,99 (π.χ. 4,99)' }, { value: 'x.00', label: 'Σε x,00 (στρογγυλό)' }, ] // ─── Condition editor ───────────────────────────────────────────────────────── function ConditionEditor({ cond, onChange, onRemove, groups, categories, prepZones }) { const set = (k, v) => onChange({ ...cond, params: { ...cond.params, [k]: v } }) const setType = t => onChange({ condition_type: t, params: {} }) return (
{/* Params per type */} {cond.condition_type === 'time_range' && (
set('from', e.target.value)} />
set('to', e.target.value)} />
)} {cond.condition_type === 'date_range' && (
set('from', e.target.value)} />
set('to', e.target.value)} />
)} {cond.condition_type === 'specific_date' && (