'use client'; export const dynamic = 'force-dynamic'; import { useEffect, useState } from 'react'; import { useParams, useRouter, usePathname } from 'next/navigation'; import { useLocale, useTranslations } from 'next-intl'; import CurateSpecialEditor, { CurateSpecial } from '@/components/CurateSpecialEditor'; import { getCuratorAuthHeaders } from '@/lib/curatorAuth'; import HelpTooltip from '@/components/HelpTooltip'; export default function CuratorSpecialEditorPage() { const params = useParams(); 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 tHelp = useTranslations('CuratorHelp'); const specialId = params?.id as string; const [special, setSpecial] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchSpecial = async () => { try { setLoading(true); const res = await fetch(`/api/curator/specials/${specialId}`, { headers: getCuratorAuthHeaders(), }); if (res.status === 403) { setError(t('specialForbidden')); return; } if (!res.ok) { setError('Failed to load special'); return; } const data = await res.json(); setSpecial(data); } catch (e) { setError('Failed to load special'); } finally { setLoading(false); } }; if (specialId) { fetchSpecial(); } }, [specialId, t]); const handleSaveStartTime = async (songId: number, startTime: number) => { const res = await fetch(`/api/curator/specials/${specialId}/songs`, { method: 'PUT', headers: { ...getCuratorAuthHeaders(), 'Content-Type': 'application/json', }, body: JSON.stringify({ songId, startTime }), }); if (res.status === 403) { setError(t('specialForbidden')); } else if (!res.ok) { setError('Failed to save changes'); } }; if (loading) { return (

{t('loadingData')}

); } if (error) { return (

{error}

); } if (!special) { return (

{t('specialNotFound')}

); } return (

{t('curateSpecialHeaderPrefix')}

router.push(`/${locale}/curator/specials`)} onSaveStartTime={handleSaveStartTime} backLabel={t('backToCuratorSpecials')} headerPrefix={t('curateSpecialHeaderPrefix')} noSongsHint={t('curateSpecialNoSongs')} noSongsSubHint={t('curateSpecialNoSongsSub')} instructionsText={t('curateSpecialInstructions')} savingLabel={t('saving')} saveChangesLabel={t('saveChanges')} savedLabel={t('saved')} />
); }