/* Relay — All Orders screen (full history, filter + sort) */ function AllOrdersScreen({ allOrders, now, onOpen }) { const { PLATFORMS, STATUS, FLOW_LABELS } = window.RelayData; const [search, setSearch] = React.useState(""); const [typeFilter, setTypeFilter] = React.useState("all"); const [statusFilter, setStatusFilter] = React.useState("all"); const [platFilter, setPlatFilter] = React.useState("all"); const [sort, setSort] = React.useState({ col: "placedAt", dir: "desc" }); const platOptions = [{ id: "all", label: "Tüm kanallar" }, ...Object.values(PLATFORMS).map((p) => ({ id: p.id, label: p.name }))]; const rows = React.useMemo(() => { const q = search.trim().toLowerCase(); let r = allOrders.filter((o) => { if (typeFilter !== "all" && o.type !== typeFilter) return false; if (statusFilter !== "all" && o.status !== statusFilter) return false; if (platFilter !== "all" && o.platformId !== platFilter) return false; if (q) { const hay = (o.customer + " " + o.id + " " + o.channelRef + " " + PLATFORMS[o.platformId].name).toLowerCase(); if (!hay.includes(q)) return false; } return true; }); const dir = sort.dir === "asc" ? 1 : -1; r = [...r].sort((a, b) => { let av = a[sort.col], bv = b[sort.col]; if (sort.col === "items") { av = a.items.reduce((s, it) => s + it.qty, 0); bv = b.items.reduce((s, it) => s + it.qty, 0); } if (sort.col === "platform") { av = PLATFORMS[a.platformId].name; bv = PLATFORMS[b.platformId].name; } return (av > bv ? 1 : av < bv ? -1 : 0) * dir; }); return r; }, [allOrders, search, typeFilter, statusFilter, platFilter, sort]); const statusOpts = [{ id: "all", label: "Tüm durumlar" }, ...["new", "preparing", "ready", "completed", "cancelled"].map((k) => ({ id: k, label: STATUS[k].label }))]; const COLS = "150px 120px 1fr 90px 80px 120px 130px 90px"; const Select = ({ value, onChange, options }) => ( ); return ( } subtitle={`Tüm kanallardaki ve durumlardaki ${allOrders.length} sipariş.`}>
setSearch(e.target.value)} placeholder="Sipariş ara…" style={{ padding: "8px 12px 8px 34px", borderRadius: "var(--radius-sm)", border: "1px solid var(--border)", background: "var(--surface)", fontSize: 13, width: 220, outline: "none" }} />
{/* filter bar */}
{rows.length} sonuç
{/* table */}
{rows.length === 0 &&
Bu filtrelere uygun sipariş bulunamadı.
} {rows.slice(0, 200).map((o) => (
onOpen(o)} style={{ display: "grid", gridTemplateColumns: COLS, gap: 12, padding: "11px 18px", borderBottom: "1px solid var(--border)", alignItems: "center", cursor: "pointer", transition: "background .1s" }} onMouseEnter={(e) => e.currentTarget.style.background = "var(--surface-2)"} onMouseLeave={(e) => e.currentTarget.style.background = "transparent"}>
{clockTime(o.placedAt)}
{new Date(o.placedAt).toLocaleDateString("tr-TR", { day: "2-digit", month: "short" })}
{o.id}
{o.customer}
{PLATFORMS[o.platformId].name} · {o.fulfillment}
{o.items.reduce((s, it) => s + it.qty, 0)} {fmtMoney(o.total)}
))}
{rows.length > 200 &&
İlk 200 sipariş gösteriliyor (Toplam {rows.length})
} ); } Object.assign(window, { AllOrdersScreen });