import { MESSAGES, type Locale } from '@/lib/i18n';

type LegalSection = {
  heading?: string;
  paragraphs?: string[];
  lines?: string[];
  list?: string[];
};

export function LegalDocument({
  locale,
  page
}: {
  locale: Locale;
  page: 'impressum' | 'privacy' | 'terms';
}) {
  const legal = MESSAGES[locale].legal[page];
  const sections = legal.sections as LegalSection[];

  return (
    <>
      <p className="text-sm text-muted-foreground">{MESSAGES[locale].legal.updated}</p>
      {sections.map((section) => (
        <section key={section.heading} className="space-y-3">
          {section.heading ? <h2 className="text-lg font-semibold">{section.heading}</h2> : null}
          {section.paragraphs?.map((paragraph) => (
            <p key={paragraph.slice(0, 48)} className="text-sm leading-relaxed text-muted-foreground">
              {paragraph}
            </p>
          ))}
          {section.lines && section.lines.length > 0 ? (
            <p className="whitespace-pre-line text-sm leading-relaxed text-muted-foreground">
              {section.lines.join('\n')}
            </p>
          ) : null}
          {section.list && section.list.length > 0 ? (
            <ul className="list-disc space-y-1 pl-5 text-sm leading-relaxed text-muted-foreground">
              {section.list.map((item) => (
                <li key={item.slice(0, 48)}>{item}</li>
              ))}
            </ul>
          ) : null}
        </section>
      ))}
    </>
  );
}
