'use client'; import { useEffect, useState } from 'react'; import { useRouter, usePathname } from 'next/navigation'; import { useLocale, useTranslations } from 'next-intl'; import { Link } from '@/lib/navigation'; import { getCuratorAuthHeaders } from '@/lib/curatorAuth'; import { getLocalizedValue } from '@/lib/i18n'; interface CuratorSpecial { id: number; name: string | { de?: string; en?: string }; songCount: number; } export default function CuratorSpecialsClient() { const router = useRouter(); const pathname = usePathname(); const urlLocale = pathname?.split('/')[1] as 'de' | 'en' | undefined; const intlLocale = useLocale() as 'de' | 'en'; const locale: 'de' | 'en' = urlLocale === 'de' || urlLocale === 'en' ? urlLocale : intlLocale; const t = useTranslations('Curator'); 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) { if (res.status === 403) { setError(t('specialForbidden')); } else { setError('Failed to load specials'); } return; } const data = await res.json(); setSpecials(data); } catch (e) { setError('Failed to load specials'); } finally { setLoading(false); } }; fetchSpecials(); }, [t]); if (loading) { return (

{t('loading')}

); } if (error) { return (

{error}

{t('backToDashboard') || 'Back to Dashboard'}
); } return (

{t('curateSpecialsTitle') || 'Curate Specials'}

{t('backToDashboard') || 'Back to Dashboard'}
{specials.length === 0 ? (

{t('noSpecialsAssigned') || 'No specials assigned to you.'}

) : (
{specials.map((special) => ( { e.currentTarget.style.background = '#f3f4f6'; e.currentTarget.style.borderColor = '#d1d5db'; }} onMouseLeave={(e) => { e.currentTarget.style.background = '#f9fafb'; e.currentTarget.style.borderColor = '#e5e7eb'; }} >

{getLocalizedValue(special.name, locale)}

{special.songCount} {special.songCount === 1 ? 'song' : 'songs'}

))}
)}
); }