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

const DEFAULT_HTML: string | null = "<input data-c42-clipboard-source value=\"npm i @42/core\" readonly />\n  <button data-c42-clipboard-trigger>\n    <span data-c42-clipboard-copy>Copy</span>\n    <span data-c42-clipboard-copied hidden>Copied!</span>\n  </button>";

export interface ClipboardProps extends Partial<ClipboardOptions> {
  /** Element/tag rendered as the controller root. Defaults to `"div"`. */
  as?: ElementType;
  className?: string;
  children?: ReactNode;
  /** Fired on `clipboard:copy` — detail: `{ text }` */
  onCopy?: (detail: unknown, event: CustomEvent) => void;
  /** Fired on `clipboard:error` — detail: `{ error }` */
  onError?: (detail: unknown, event: CustomEvent) => void;
  /** Extra props are forwarded to the rendered `<div>` element. */
  [key: string]: unknown;
}

export function Clipboard(props: ClipboardProps) {
  const { as, className, children, onCopy, onError, text, timeout, ...rest } = props;
  const options = { text, timeout } as ClipboardOptions;

  return (
    <C42
      controller={ClipboardController}
      options={options}
      deps={[text, timeout]}
      events={{
        'clipboard:copy': onCopy,
        'clipboard:error': onError,
      }}
      as={(as as ElementType) ?? 'div'}
      className={className as string | undefined}
      html={DEFAULT_HTML ?? undefined}
      {...{ 'data-c42-clipboard': '' }}
      {...rest}
    >
      {children as ReactNode}
    </C42>
  );
}
