/**
 * Inline rich-text block — fully driven by the merchant's dashboard.
 *
 * The merchant configures rich-text blocks in the Brainerce dashboard
 * under Sell → Content → Rich Text. Use this component anywhere on a page
 * to drop a merchant-editable HTML block (intro copy, banner descriptions,
 * inline announcements that aren't tied to the top-of-page Announcement
 * bar, etc.).
 *
 * Security: HTML is sanitized via `sanitizeHtml` (isomorphic-dompurify)
 * before injecting via dangerouslySetInnerHTML.
 */
import * as React from 'react';
import type { Content } from 'brainerce';
import { sanitizeHtml } from '@/core/lib/sanitize';

interface RichTextBlockProps {
  /** Pre-fetched RICH_TEXT row, e.g. via `client.content.richText.get(key, locale)`. */
  block: Content<'RICH_TEXT'> | null;
  /** Optional wrapper className for layout positioning. */
  className?: string;
}

export function RichTextBlock({ block, className }: RichTextBlockProps) {
  if (!block?.data?.html) return null;
  return (
    <div
      className={className ?? 'prose prose-sm dark:prose-invert max-w-none'}
      dangerouslySetInnerHTML={{ __html: sanitizeHtml(block.data.html) }}
    />
  );
}
