'use client'; import { useState, useEffect, useMemo } from 'react'; import { Radio } from 'lucide-react'; import { useLanguage } from '@/lib/i18n/LanguageContext'; import SlotFilterBar, { LOCATIONS } from '@/components/slots/SlotFilterBar'; import SlotGrid from '@/components/slots/SlotGrid'; import { SlotSnapshot } from '@/types'; import { statsService } from '@/lib/services'; export default function SlotDashboardPage() { const { t } = useLanguage(); const [loading, setLoading] = useState(true); const [snapshots, setSnapshots] = useState([]); const [selectedCountryCode, setSelectedCountryCode] = useState('IE'); const [selectedCity, setSelectedCity] = useState('Dublin'); const currentCities = useMemo(() => { return LOCATIONS.find((l) => l.code === selectedCountryCode)?.cities || []; }, [selectedCountryCode]); const handleCountryChange = (code: string) => { setSelectedCountryCode(code); const countryData = LOCATIONS.find((l) => l.code === code); if (countryData && countryData.cities.length > 0) { setSelectedCity(countryData.cities[0]); } else { setSelectedCity(''); } }; const fetchDashboard = async () => { setLoading(true); try { const res = await statsService.getSlotsOverview(selectedCity); const data = res?.data || []; // 过滤当前城市 const filtered = data.filter((i: SlotSnapshot) => i.city === selectedCity); // 排序: Available > Waitlist > None filtered.sort((a: SlotSnapshot, b: SlotSnapshot) => { const score = (s: string) => (s === 'Available' ? 3 : s === 'Waitlist' ? 2 : 1); return score(b.availability_status) - score(a.availability_status); }); setSnapshots(filtered); } catch (e) { console.warn('Fetch slots failed', e); setSnapshots([]); } finally { setLoading(false); } }; useEffect(() => { if (selectedCity) { fetchDashboard(); } }, [selectedCity]); return (
{/* 顶部雷达标头卡片 */}
[ {t('slots.title')} ]
{t('slots.updated_at')}

{t('slots.title') || '实时使馆名额雷达监控'}

{t('slots.subtitle') || '查看预约名额记录,并留意数据更新时间。'}

{/* Filter Bar 组件 */} {/* Grid List 组件 */}
); }