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

const DEFAULT_HTML: string | null = "<button data-c42-modal-trigger>Open</button>\n  <div data-c42-modal-overlay>\n    <div data-c42-modal-content>\n      <button data-c42-modal-close>×</button>\n      <p>Modal body</p>\n    </div>\n  </div>";

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

export function Modal(props: ModalProps) {
  const { as, className, children, onOpen, onClose, closeOnOverlayClick, closeOnEscape, lockScroll, defaultOpen, ...rest } = props;
  const options = { closeOnOverlayClick, closeOnEscape, lockScroll, defaultOpen } as ModalOptions;

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