import { describe, it, expect } from 'vitest';
import { selectFilteredNotes } from '../../src/renderer/inbox/selectFilteredNotes.js';
import type { Note } from '@shared/types';

function sample(id: string, tags: string[]): Note {
  return {
    id,
    rawText: 'x',
    aiTitle: null,
    aiSummary: null,
    aiStatus: 'done',
    aiError: null,
    aiProvider: null,
    aiGeneratedAt: null,
    titleEditedByUser: false,
    summaryEditedByUser: false,
    userIntent: null,
    intentPromptedAt: null,
    dueDate: null,
    dueDateEditedByUser: false,
    deletedAt: null,
    lastRecalledAt: null,
    recallDismissedAt: null,
    status: 'active',
    statusChangedAt: null,
    moveReason: null,
    createdAt: '2026-04-26T00:00:00Z',
    updatedAt: '2026-04-26T00:00:00Z',
    tags: tags.map((name) => ({ name, source: 'ai' as const })),
    media: []
  };
}

describe('selectFilteredNotes', () => {
  it('returns all notes when filter is null', () => {
    const notes = [sample('a', ['x']), sample('b', ['y'])];
    expect(selectFilteredNotes({ notes, tagFilter: null }).length).toBe(2);
  });

  it('filters to notes containing the tag', () => {
    const notes = [sample('a', ['pr', 'review']), sample('b', ['demo'])];
    const out = selectFilteredNotes({ notes, tagFilter: 'pr' });
    expect(out.length).toBe(1);
    expect(out[0]!.id).toBe('a');
  });

  it('empty filter result when tag not present', () => {
    const notes = [sample('a', ['x'])];
    expect(selectFilteredNotes({ notes, tagFilter: 'missing' }).length).toBe(0);
  });

  it('matches against any tag of the note', () => {
    const notes = [sample('a', ['alpha', 'beta', 'gamma'])];
    expect(selectFilteredNotes({ notes, tagFilter: 'gamma' }).length).toBe(1);
  });
});
