'use client'; import { useEffect, useState } from 'react'; import { useLocale, useTranslations } from 'next-intl'; import { Link } from '@/lib/navigation'; import { getCuratorAuthHeaders } from '@/lib/curatorAuth'; import HelpTooltip from '@/components/HelpTooltip'; type LocalizedString = string | { de: string; en: string }; interface CuratorSpecialSummary { id: number; name: LocalizedString; songCount: number; } export default function CuratorSpecialsPage() { const t = useTranslations('Curator'); const tHelp = useTranslations('CuratorHelp'); const locale = useLocale(); const [specials, setSpecials] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchSpecials = async () => { try { setLoading(true); const res = await fetch('/api/curator/specials', { headers: getCuratorAuthHeaders(), }); if (res.ok) { const data = await res.json(); setSpecials(data); } else if (res.status === 403) { setError(t('noSpecialPermissions')); } else { setError('Failed to load specials'); } } catch (e) { setError('Failed to load specials'); } finally { setLoading(false); } }; fetchSpecials(); }, [t]); if (loading) { return (

{t('loadingData')}

); } if (error) { return (

{error}

); } if (specials.length === 0) { return (

{t('noSpecialsInScope')}

{t('backToDashboard')}
); } const resolveLocalized = (value: LocalizedString, locale: string): string => { if (!value) return ''; if (typeof value === 'string') return value; const loc = locale === 'de' || locale === 'en' ? locale : 'en'; return value[loc] ?? value.en ?? value.de; }; return (

{t('curateSpecialsTitle')}

{t('backToDashboard')}

{t('curateSpecialsDescription')}

{specials.map(special => (

{resolveLocalized(special.name, String(locale))}

{t('curateSpecialSongCount', { count: special.songCount })}

{t('curateSpecialOpen')}
))}
); }