import type { Row } from '@tanstack/angular-table';
import type { DataTableColumnDef } from '../../components/data-table/types';
import { useDataTable, type DataTableResult } from './use-data-table';

export interface StaticDataTableConfig<T> {
  readonly rows: () => T[];
  readonly columns: DataTableColumnDef<T>[] | (() => DataTableColumnDef<T>[]);
  readonly pageSize?: number;
  readonly getRowId?: (row: T, index: number) => string;
  readonly enableRowSelection?: boolean | ((row: Row<T>) => boolean);
}

/**
 * Preset for in-memory tables. Sort, pagination and filtering happen
 * client-side. Composes the same atoms as `usePaginatedDataTable` but with
 * `manualSorting/manualPagination = false` so TanStack handles them
 * locally over the input rows.
 *
 * Use for storybook stories, tests, or any view where the full dataset is
 * already in memory and pagination is purely cosmetic.
 */
export function useStaticDataTable<T>(config: StaticDataTableConfig<T>): DataTableResult<T> {
  return useDataTable<T>({
    data: config.rows,
    columns: config.columns,
    pageSize: config.pageSize,
    manualSorting: false,
    manualPagination: false,
    getRowId: config.getRowId,
    enableRowSelection: config.enableRowSelection,
  });
}
