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

const DEFAULT_HTML: string | null = "<button data-c42-popover-trigger>Open</button>\n  <div data-c42-popover-content>\n    <a href=\"#\">A link</a>\n    <button>An action</button>\n  </div>";

export interface PopoverProps extends Partial<PopoverOptions> {
  /** Element/tag rendered as the controller root. Defaults to `"div"`. */
  as?: ElementType;
  className?: string;
  children?: ReactNode;
  /** Fired on `popover:open` — detail: `(no detail)` */
  onOpen?: (detail: unknown, event: CustomEvent) => void;
  /** Fired on `popover:close` — detail: `(no detail)` */
  onClose?: (detail: unknown, event: CustomEvent) => void;
  /** Extra props are forwarded to the rendered `<div>` element. */
  [key: string]: unknown;
}

export function Popover(props: PopoverProps) {
  const { as, className, children, onOpen, onClose, placement, offset, autoFocus, trapFocus, closeOnOutsideClick, ...rest } = props;
  const options = { placement, offset, autoFocus, trapFocus, closeOnOutsideClick } as PopoverOptions;

  return (
    <C42
      controller={PopoverController}
      options={options}
      deps={[placement, offset, autoFocus, trapFocus, closeOnOutsideClick]}
      events={{
        'popover:open': onOpen,
        'popover:close': onClose,
      }}
      as={(as as ElementType) ?? 'div'}
      className={className as string | undefined}
      html={DEFAULT_HTML ?? undefined}
      {...{ 'data-c42-popover': '' }}
      {...rest}
    >
      {children as ReactNode}
    </C42>
  );
}
