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

const DEFAULT_HTML: string | null = "<button data-c42-select-trigger><span data-c42-select-value>Choose…</span></button>\n  <div data-c42-select-listbox>\n    <div data-c42-select-option data-value=\"a\">Apple</div>\n    <div data-c42-select-option data-value=\"b\">Banana</div>\n  </div>";

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

export function Select(props: SelectProps) {
  const { as, className, children, onChange, onOpen, onClose, defaultValue, placeholder, ...rest } = props;
  const options = { defaultValue, placeholder } as SelectOptions;

  return (
    <C42
      controller={SelectController}
      options={options}
      deps={[defaultValue, placeholder]}
      events={{
        'select:change': onChange,
        'select:open': onOpen,
        'select:close': onClose,
      }}
      as={(as as ElementType) ?? 'div'}
      className={className as string | undefined}
      html={DEFAULT_HTML ?? undefined}
      {...{ 'data-c42-select': '' }}
      {...rest}
    >
      {children as ReactNode}
    </C42>
  );
}
