/**
 * Sanitizer for admin-authored HTML coming from the CMS (`content_en` /
 * `content_ar` on `GET /pages/{slug}/`).
 *
 * Dashboard editors are trusted-ish, not trusted: the markup is still rendered
 * with `dangerouslySetInnerHTML`, so it goes through DOMPurify with an
 * allowlist first. For server-rendered pages, sanitize on the SERVER and pass the resulting string down —
 * `isomorphic-dompurify` pulls in jsdom on Node, which has no business in the
 * client bundle. Client-fetched legal dialogs use browser DOMPurify with the same
 * allowlist from cmsHtmlPolicy.ts.
 */
import DOMPurify from "isomorphic-dompurify";

import { CMS_HTML_POLICY } from "./cmsHtmlPolicy";

export function sanitizeCmsHtml(html: string | null | undefined): string {
  if (!html) return "";
  return DOMPurify.sanitize(html, CMS_HTML_POLICY);
}
