// AUTO-GENERATED by scripts/generate-wrappers.mjs — do not edit by hand.
// Source: packages/core/manifest.json (component "rich-text-editor").
import type { ElementType, ReactNode } from 'react';
import { RichTextEditor as RichTextEditorController, type RichTextEditorOptions } from '@42/core/rich-text-editor';
import { C42 } from '../C42';

const DEFAULT_HTML: string | null = "<div data-c42-rte-toolbar>\n    <button data-c42-rte-command=\"bold\" aria-label=\"Bold\"><b>B</b></button>\n    <button data-c42-rte-command=\"italic\" aria-label=\"Italic\"><i>I</i></button>\n    <button data-c42-rte-command=\"insertUnorderedList\" aria-label=\"List\">• List</button>\n    <button data-c42-rte-command=\"createLink\" aria-label=\"Link\">Link</button>\n  </div>\n  <div data-c42-rte-content data-placeholder=\"Write something…\"></div>";

export interface RichTextEditorProps extends Partial<RichTextEditorOptions> {
  /** Element/tag rendered as the controller root. Defaults to `"div"`. */
  as?: ElementType;
  className?: string;
  children?: ReactNode;
  /** Fired on `richtexteditor:command` — detail: `{ command, value? }` */
  onCommand?: (detail: unknown, event: CustomEvent) => void;
  /** Fired on `richtexteditor:change` — detail: `{ html }` */
  onChange?: (detail: unknown, event: CustomEvent) => void;
  /** Extra props are forwarded to the rendered `<div>` element. */
  [key: string]: unknown;
}

export function RichTextEditor(props: RichTextEditorProps) {
  const { as, className, children, onCommand, onChange, value, getLinkUrl, ...rest } = props;
  const options = { value, getLinkUrl } as RichTextEditorOptions;

  return (
    <C42
      controller={RichTextEditorController}
      options={options}
      deps={[value, getLinkUrl]}
      events={{
        'richtexteditor:command': onCommand,
        'richtexteditor:change': onChange,
      }}
      as={(as as ElementType) ?? 'div'}
      className={className as string | undefined}
      html={DEFAULT_HTML ?? undefined}
      {...{ 'data-c42-rich-text-editor': '' }}
      {...rest}
    >
      {children as ReactNode}
    </C42>
  );
}
