import type { Note } from '@shared/types';

/**
 * Pure selector for tag-based filtering.
 *
 * Extracted out of `store.ts` so unit tests can import it under the
 * vitest `node` environment without pulling in `api.ts`, which touches
 * `window.inkling` at module-load time.
 */
export function selectFilteredNotes(state: {
  notes: Note[];
  tagFilter: string | null;
}): Note[] {
  if (state.tagFilter === null) return state.notes;
  const target = state.tagFilter;
  return state.notes.filter((n) => n.tags.some((t) => t.name === target));
}
