/* Relay — POS / New manual (phone) order */
function POSScreen({ branch, onPlace, onCancel }) {
const { CATALOG, FULFILLMENT, createManualOrder } = window.RelayData;
const [type, setType] = React.useState("food");
const [cat, setCat] = React.useState("all");
const [search, setSearch] = React.useState("");
const [cart, setCart] = React.useState([]); // {id,name,price,qty,mods:[]}
const [customer, setCustomer] = React.useState("");
const [phone, setPhone] = React.useState("");
const [area, setArea] = React.useState("");
const [fulfillment, setFulfillment] = React.useState("Pickup");
const [note, setNote] = React.useState("");
const menu = CATALOG.filter((i) => i.type === type && i.available);
const categories = React.useMemo(() => ["all", ...[...new Set(menu.map((i) => i.category))].sort()], [type]);
React.useEffect(() => { setCat("all"); setFulfillment(FULFILLMENT[type][0]); }, [type]);
const shown = menu.filter((i) => (cat === "all" || i.category === cat) &&
(!search.trim() || i.name.toLowerCase().includes(search.trim().toLowerCase())));
function addToCart(item) {
setCart((prev) => {
const ex = prev.find((c) => c.id === item.id && c.mods.length === 0);
if (ex) return prev.map((c) => c === ex ? { ...c, qty: c.qty + 1 } : c);
return [...prev, { id: item.id, name: item.name, price: item.price, qty: 1, mods: [] }];
});
}
function setQty(idx, delta) {
setCart((prev) => prev.map((c, i) => i === idx ? { ...c, qty: Math.max(0, c.qty + delta) } : c).filter((c) => c.qty > 0));
}
function toggleMod(idx, mod) {
setCart((prev) => prev.map((c, i) => i === idx ? { ...c, mods: c.mods.includes(mod) ? c.mods.filter((m) => m !== mod) : [...c.mods, mod] } : c));
}
const subtotal = cart.reduce((s, c) => s + c.price * c.qty, 0);
const count = cart.reduce((s, c) => s + c.qty, 0);
const canPlace = cart.length > 0;
function place() {
if (!canPlace) return;
const order = createManualOrder({
type, customer: customer.trim(), phone: phone.trim(), area: area.trim(),
fulfillment, note: note.trim(),
items: cart.map((c) => ({ name: c.name, qty: c.qty, price: c.price, sku: null, mods: c.mods })),
branchId: branch.id,
});
onPlace(order);
}
const catModsFor = (id) => (CATALOG.find((c) => c.id === id) || {}).mods || [];
return (
{/* LEFT: catalog picker */}
Yeni sipariş
Telefon / Gel-Al · {branch.name}
{categories.map((c) => (
))}
{shown.map((it) => (
))}
{shown.length === 0 &&
Ürün bulunamadı.
}
{/* RIGHT: cart / ticket */}
Sipariş Fişi
{count} ürün
{/* cart items */}
{cart.length === 0 ? (
Henüz ürün eklenmedi
Sipariş oluşturmak için soldaki ürünlere dokunun.
) : (
{cart.map((c, idx) => {
const mods = catModsFor(c.id);
return (
{c.name}
AED {c.price} adet
{fmtMoney(c.price * c.qty)}
{mods.length > 0 && (
{mods.map((m) => {
const on = c.mods.includes(m);
return ;
})}
)}
{c.qty}
);
})}
)}
{/* customer details + place */}
Teslimat Şekli
{FULFILLMENT[type].map((f) => (
))}
Toplam
AED {fmtMoney(subtotal)}
Siparişi ver · mutfağa gönder
);
}
function FieldLabel({ children }) {
return ;
}
function Field({ label, value, onChange, placeholder, mono }) {
return (
{label}
onChange(e.target.value)} placeholder={placeholder} className={mono ? "mono" : ""} style={{ width: "100%", padding: "8px 10px", borderRadius: 7, border: "1px solid var(--border-strong)", background: "var(--surface)", fontSize: 13, outline: "none" }} />
);
}
Object.assign(window, { POSScreen });