import { useEffect, useMemo, useState } from "react"; import { useLocation, useNavigate, useParams } from "react-router-dom"; import Icon from "../components/Icon"; import { CafeEvent, mockCafeEvents } from "../data/mockCafeEvents"; import { EventReservation, fetchEventReservations } from "../services/campaignApi"; import { getCafeUuid } from "../utils/cafe"; import HostBanner from "../assets/images/banners/Host-banner.jpg"; import { formatPersianNumber } from "../utils/formatNumber"; function toEnglishDigits(value: string) { const persianDigits = "۰۱۲۳۴۵۶۷۸۹"; return value.replace(/[۰-۹]/g, (digit) => String(persianDigits.indexOf(digit)), ); } function reservationMatches(reservation: EventReservation, query: string) { if (!query) return true; const haystack = toEnglishDigits( `${reservation.full_name} ${reservation.phone_number} ${reservation.people_count} ${formatPersianNumber(reservation.people_count)} ${reservation.reserve_code}`, ).toLowerCase(); return haystack.includes(toEnglishDigits(query).toLowerCase()); } function downloadReservationsCsv(reservations: EventReservation[]) { const header = ["کد رزرو", "تعداد", "نام", "شماره تماس"]; const rows = reservations.map((r) => [ r.reserve_code, String(r.people_count), r.full_name, toEnglishDigits(r.phone_number), ]); const csvContent = [header, ...rows] .map((row) => row.map((cell) => `"${cell.replace(/"/g, '""')}"`).join(",")) .join("\n"); const blob = new Blob(["" + csvContent], { type: "text/csv;charset=utf-8;", }); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = "reservations.csv"; link.click(); URL.revokeObjectURL(url); } function ReservationCard({ reservation, selected, onToggle, }: { reservation: EventReservation; selected: boolean; onToggle: () => void; }) { return (
{reservation.full_name}
{reservation.phone_number}