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

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

/**
 * Atom: column visibility. Single responsibility — owns a `VisibilityState`
 * signal. Persistence-by-gridId is delegated to a separate wrapper
 * composable (not part of this atom) to keep the responsibility unitary.
 */
export function useTableColumnVisibility(initial: VisibilityState = {}): TableColumnVisibilityAtom {
  const state = signal(initial);
  return {
    state: state.asReadonly(),
    set: (s: VisibilityState) => state.set(s),
  };
}
