import { signal, type Signal } from '@angular/core';
import type { ColumnOrderState } from '@tanstack/angular-table';

export interface TableColumnOrderAtom {
  readonly state: Signal<ColumnOrderState>;
  set(s: ColumnOrderState): void;
}

/**
 * Atom: column order. Single responsibility — owns a `ColumnOrderState`
 * signal (an array of column ids in display order).
 */
export function useTableColumnOrder(initial: ColumnOrderState = []): TableColumnOrderAtom {
  const state = signal(initial);
  return {
    state: state.asReadonly(),
    set: (s: ColumnOrderState) => state.set(s),
  };
}
