/**
 * `<table-toolbar-ui>` — Header / companion bar for a sibling table-ui. Renders title + count badge, filter / sort / columns popovers, and a search input — all wired to the target table via an [for] id-ref. Modeled on chart-legend-ui's [for] binding pattern. Drop next to (or above) any table-ui to add the standard data-grid toolbar without re-implementing search, filter, sort, or column visibility. Filter rows auto-pick a primitive per column: ≤ 50 distinct values → multi- select (searchable when ≥ 12 options), id-like keys → free-text contains. The column descriptor's `filter` field overrides the auto-detect: `'select'` forces multi-select even on high-cardinality columns; `'text'` forces a contains input even on small enums.
 *
 * @see https://ui-kit.exe.xyz/site/components/table-toolbar
 *
 * Type declarations generated by scripts/build/dts-codegen.mjs from
 * the component's `.a2ui.json` sidecar(s). Edit the source `.yaml`,
 * run `npm run build:components`, then `npm run codegen:dts` to
 * regenerate; or hand-author this file fully if rich event types are
 * needed beyond what the yaml `events:` block can express.
 */

import { UIElement } from '../../core/element.js';

export type TableToolbarColumnsChangeEvent = CustomEvent<unknown>;
export type TableToolbarFilterChangeEvent = CustomEvent<unknown>;
export type TableToolbarSearchEvent = CustomEvent<unknown>;
export type TableToolbarSortChangeEvent = CustomEvent<unknown>;

export class UITableToolbar extends UIElement {
  /** Optional count badge value shown next to the title. When unset, falls back to the row count of the bound table. */
  count: string;
  /** id-ref of the table-ui to control. Falls back to the first sibling table-ui within the same parent when omitted. */
  for: string;
  /** Hide the Columns visibility popover button. Columns control is shown by default; set to opt out. */
  noColumns: boolean;
  /** Hide the Filter popover button. Filter is shown by default; set to opt out. */
  noFilter: boolean;
  /** Hide the search input. Search is shown by default; set to opt out. */
  noSearch: boolean;
  /** Hide the Sort popover button. Sort is shown by default; set to opt out. */
  noSort: boolean;
  /** Placeholder text for the search input. */
  placeholder: string;
  /** Title text shown on the left. */
  text: string;
  /** Toolbar visual variant. `default` renders bare on parent surface; `card` adds the same chrome as a card-ui header. */
  variant: 'default' | 'card';

  addEventListener<K extends keyof HTMLElementEventMap>(
    type: K,
    listener: (this: UITableToolbar, ev: HTMLElementEventMap[K]) => unknown,
    options?: boolean | AddEventListenerOptions,
  ): void;
  addEventListener(type: 'columns-change', listener: (ev: TableToolbarColumnsChangeEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
  addEventListener(type: 'filter-change', listener: (ev: TableToolbarFilterChangeEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
  addEventListener(type: 'search', listener: (ev: TableToolbarSearchEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
  addEventListener(type: 'sort-change', listener: (ev: TableToolbarSortChangeEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
}
