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

const DEFAULT_HTML: string | null = "<thead><tr>\n    <th data-c42-sortable-col data-value=\"name\">\n      Name<span data-c42-sortable-resize></span>\n    </th>\n  </tr></thead>\n  <tbody>\n    <tr data-c42-sortable-row data-value=\"r1\">\n      <td><button data-c42-sortable-row-handle></button>Ada</td>\n    </tr>\n  </tbody>";

export interface SortableTableProps extends Partial<SortableTableOptions> {
  /** Element/tag rendered as the controller root. Defaults to `"table"`. */
  as?: ElementType;
  className?: string;
  children?: ReactNode;
  /** Fired on `sortabletable:reorder` — detail: `{ axis, from, to, order }` */
  onReorder?: (detail: unknown, event: CustomEvent) => void;
  /** Fired on `sortabletable:resize` — detail: `{ value, width }` */
  onResize?: (detail: unknown, event: CustomEvent) => void;
  /** Extra props are forwarded to the rendered `<table>` element. */
  [key: string]: unknown;
}

export function SortableTable(props: SortableTableProps) {
  const { as, className, children, onReorder, onResize, reorderRows, reorderColumns, resizeColumns, resizeStep, minColumnWidth, ...rest } = props;
  const options = { reorderRows, reorderColumns, resizeColumns, resizeStep, minColumnWidth } as SortableTableOptions;

  return (
    <C42
      controller={SortableTableController}
      options={options}
      deps={[reorderRows, reorderColumns, resizeColumns, resizeStep, minColumnWidth]}
      events={{
        'sortabletable:reorder': onReorder,
        'sortabletable:resize': onResize,
      }}
      as={(as as ElementType) ?? 'table'}
      className={className as string | undefined}
      html={DEFAULT_HTML ?? undefined}
      {...{ 'data-c42-sortable-table': '' }}
      {...rest}
    >
      {children as ReactNode}
    </C42>
  );
}
