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

const DEFAULT_HTML: string | null = "<div data-c42-drawer-overlay></div>\n  <div data-c42-drawer-content>\n    <button data-c42-drawer-close>Close</button>\n  </div>";

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

export function Drawer(props: DrawerProps) {
  const { as, className, children, onOpen, onClose, side, closeOnOverlayClick, closeOnEscape, lockScroll, defaultOpen, ...rest } = props;
  const options = { side, closeOnOverlayClick, closeOnEscape, lockScroll, defaultOpen } as DrawerOptions;

  return (
    <C42
      controller={DrawerController}
      options={options}
      deps={[side, closeOnOverlayClick, closeOnEscape, lockScroll, defaultOpen]}
      events={{
        'drawer:open': onOpen,
        'drawer:close': onClose,
      }}
      as={(as as ElementType) ?? 'div'}
      className={className as string | undefined}
      html={DEFAULT_HTML ?? undefined}
      {...{ 'data-c42-drawer': '' }}
      {...rest}
    >
      {children as ReactNode}
    </C42>
  );
}
