import React, { useState } from 'react'; import { AuthStatus } from '../lib/types'; import { api } from '../lib/api'; import { MarkdownViewer } from '../lib/markdown'; import { ReadingModal } from './ReadingModal'; type LegalType = 'imprint' | 'privacy'; const TITLES: Record = { imprint: 'Impressum', privacy: 'Datenschutz' }; interface LegalLinksProps { legal?: AuthStatus['legal']; className?: string; children?: React.ReactNode; // further footer links, e.g. "Über MindSift" } // Impressum / Datenschutz links: an external URL opens in a new tab, Markdown in a reading modal. // Links without URL or text are not shown at all. export const LegalLinks: React.FC = ({ legal, className = '', children }) => { const [open, setOpen] = useState<{ type: LegalType; content: string } | null>(null); const [error, setError] = useState(null); const entries = (['imprint', 'privacy'] as LegalType[]) .map((type) => ({ type, url: type === 'imprint' ? legal?.imprintUrl : legal?.privacyUrl, hasContent: type === 'imprint' ? legal?.hasImprintContent : legal?.hasPrivacyContent, })) .filter((e) => e.url || e.hasContent); if (entries.length === 0 && !children) return null; const openText = async (type: LegalType) => { setError(null); try { setOpen({ type, content: await api.getLegalText(type) }); } catch (err: any) { setError(err.message || 'Text konnte nicht geladen werden'); } }; return (
{entries.map((e) => e.url ? ( {TITLES[e.type]} ) : ( ) )} {children} {error && {error}} {open && ( setOpen(null)}> )}
); };