import React from 'react'; import { Link, useParams } from 'react-router-dom'; import { YStack, XStack } from '@tamagui/stacks'; import { SizableText as Text } from '@tamagui/text'; import { Button } from '@tamagui/button'; import { ArrowLeft, Loader2 } from 'lucide-react'; import AppShell from '../components/AppShell'; import StandaloneShell from '../components/StandaloneShell'; import SurfaceCard from '../components/SurfaceCard'; import PullToRefresh from '@/guest/components/PullToRefresh'; import { getHelpArticle, type HelpArticleDetail } from '@/guest/services/helpApi'; import { useLocale } from '@/guest/i18n/LocaleContext'; import { useTranslation } from '@/guest/i18n/useTranslation'; import EventLogo from '../components/EventLogo'; import { useGuestThemeVariant } from '../lib/guestTheme'; export default function HelpArticleScreen() { const params = useParams<{ token?: string; slug: string }>(); const slug = params.slug; const { locale } = useLocale(); const { t } = useTranslation(); const { isDark } = useGuestThemeVariant(); const mutedText = isDark ? 'rgba(248, 250, 252, 0.7)' : 'rgba(15, 23, 42, 0.65)'; const [article, setArticle] = React.useState(null); const [state, setState] = React.useState<'loading' | 'ready' | 'error'>('loading'); const basePath = params.token ? `/e/${encodeURIComponent(params.token)}/help` : '/help'; const brandName = 'Fotospiel'; const showStandaloneHeader = !params.token; const loadArticle = React.useCallback(async () => { if (!slug) { setState('error'); return; } setState('loading'); try { const result = await getHelpArticle(slug, locale); setArticle(result.article); setState('ready'); } catch (error) { console.error('[HelpArticle] Failed to load article', error); setState('error'); } }, [slug, locale]); React.useEffect(() => { loadArticle(); }, [loadArticle]); const title = state === 'loading' ? t('help.article.loadingTitle') : (article?.title ?? t('help.article.unavailable')); const wrapper = ( {showStandaloneHeader ? : null} {title} {article?.updated_at ? ( {t('help.article.updated', { date: formatDate(article.updated_at, locale) })} ) : null} {state === 'loading' ? ( {t('help.article.loadingDescription')} ) : null} {state === 'error' ? ( {t('help.article.unavailable')} ) : null} {state === 'ready' && article ? (
{article.related && article.related.length > 0 ? ( {t('help.article.relatedTitle')} {article.related.map((rel) => ( ))} ) : null} ) : null} ); if (params.token) { return {wrapper}; } return {wrapper}; } function formatDate(value: string, locale: string): string { try { return new Date(value).toLocaleDateString(locale, { day: '2-digit', month: 'short', year: 'numeric', }); } catch { return value; } }