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

const DEFAULT_HTML: string | null = "<button data-c42-dropdown-trigger>Menu</button>\n  <div data-c42-dropdown-menu>\n    <button data-c42-dropdown-item>Option 1</button>\n    <button data-c42-dropdown-item>Option 2</button>\n  </div>";

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

export function Dropdown(props: DropdownProps) {
  const { as, className, children, onOpen, onClose, placement, offset, closeOnSelect, ...rest } = props;
  const options = { placement, offset, closeOnSelect } as DropdownOptions;

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