import { ReactNode, useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import Icon from "../components/Icon"; import SupportButton from "../components/SupportButton"; import LogoutModal from "../components/LogoutModal"; import { logout } from "../utils/logout"; import { useNow } from "../hooks/useNow"; import { CafeSchedule, fetchCafeSchedules } from "../services/campaignApi"; import { getCafeUuid } from "../utils/cafe"; import HostBanner from "../assets/images/banners/Host-banner.jpg"; import { formatPersianNumber } from "../utils/formatNumber"; import { formatMatchLabel } from "../utils/matchCountdown"; function PanelRow({ icon, label, onClick, }: { icon: ReactNode; label: string; onClick?: () => void; }) { return ( {icon} {label} ); } export default function CafeOwnerPanel() { const navigate = useNavigate(); const now = useNow(); const [schedules, setSchedules] = useState([]); const [showLogout, setShowLogout] = useState(false); useEffect(() => { const cafeUuid = getCafeUuid(); if (!cafeUuid) return; fetchCafeSchedules(cafeUuid) .then(setSchedules) .catch(() => {}); }, []); return ( setShowLogout(true)} className="absolute left-3 top-3 flex items-center gap-1.5 rounded-full bg-white/90 px-3 py-1.5 text-sm font-semibold text-gray-800 shadow" > خروج {showLogout && ( { logout(); navigate("/cafe/login"); }} onCancel={() => setShowLogout(false)} /> )} پنل کافه } label="اطلاعات کافه" onClick={() => navigate("/owner/register", { state: { step: 2 } })} /> } label="افزودن رویداد" onClick={() => navigate("/owner/events/new")} /> رویدادهای فعال شما {schedules.map((schedule) => { const isPast = new Date(schedule.match_event.match_datetime).getTime() <= now.getTime(); const matchLabel = formatMatchLabel(schedule.match_event, now); return ( {matchLabel} {isPast && ( برگزار شده )} {formatPersianNumber(schedule.remaining_tickets)} صندلی از{" "} {formatPersianNumber(schedule.total_tickets)} باقی مانده } label="مشاهده رزروها" onClick={() => navigate(`/owner/events/${schedule.uuid}/reservations`, { state: { event: { id: schedule.uuid, matchLabel, remainingSeats: schedule.remaining_tickets, totalSeats: schedule.total_tickets, }, }, }) } /> ); })} ); }
{matchLabel}