import { signal, type Signal } from '@angular/core';
import type { ColumnFilter } from '../../../components/data-table/types';

export interface TableFiltersAtom {
  readonly value: Signal<ColumnFilter[]>;
  set(f: ColumnFilter[]): void;
}

/**
 * Atom: column filters. Single responsibility — owns the catalyst-shape
 * `ColumnFilter[]` signal used by `buildFilterWhere` to assemble Sequelize
 * `where` clauses. NOT TanStack's `ColumnFiltersState` — that's a separate
 * shape used internally by TanStack which the binding layer derives if
 * needed.
 */
export function useTableFilters(initialValue: ColumnFilter[] = []): TableFiltersAtom {
  const value = signal(initialValue);
  return {
    value: value.asReadonly(),
    set: (f: ColumnFilter[]) => value.set(f),
  };
}
