// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest';
import '@testing-library/jest-dom/vitest';
import { render, screen, cleanup } from '@testing-library/react';
import React from 'react';

const baseState = {
  reviewData: {
    totalCount: 12,
    recentNotes: [],
    tagCounts: [{ tag: '회의', count: 5 }, { tag: '결재', count: 3 }],
    dueProgress: { total: 10, passed: 4, pending: 6 }
  }
};

vi.mock('../../src/renderer/inbox/api.js', () => ({
  inboxApi: {
    openMedia: vi.fn(),
    deleteNote: vi.fn(),
    restoreNote: vi.fn(),
    permanentDeleteNote: vi.fn(),
    updateAiFields: vi.fn(),
    setDueDate: vi.fn(),
    setIntent: vi.fn(),
    dismissIntent: vi.fn(),
    setStatus: vi.fn(async () => ({ ok: true as const })),
    classifyStatus: vi.fn(async () => ({ recommended: 'archived' as const, rationale: 'stub' })),
    updateRawText: vi.fn(async () => ({ ok: true as const })),
    listRevisions: vi.fn(async () => []),
    getRevision: vi.fn()
  }
}));

vi.mock('../../src/renderer/inbox/store.js', () => ({
  useInbox: Object.assign(
    (selector?: (s: typeof baseState) => unknown) => (selector ? selector(baseState) : baseState),
    { getState: () => baseState }
  )
}));

import { ReviewView } from '../../src/renderer/inbox/components/ReviewView';

describe('ReviewView', () => {
  beforeEach(() => { cleanup(); });

  it('daily — 라벨 + totalCount + tagBar + dueProgress 렌더', () => {
    render(<ReviewView period="daily" />);
    expect(screen.getByText(/일간/)).toBeInTheDocument();
    expect(screen.getByText(/총.*12건/)).toBeInTheDocument();
    expect(screen.getByText('회의')).toBeInTheDocument();
    expect(screen.getByText('결재')).toBeInTheDocument();
    expect(screen.getByText(/4.*\/.*10/)).toBeInTheDocument();
  });

  it('weekly — 라벨 weekly', () => {
    render(<ReviewView period="weekly" />);
    expect(screen.getByText(/주간/)).toBeInTheDocument();
  });

  it('monthly — 라벨 monthly', () => {
    render(<ReviewView period="monthly" />);
    expect(screen.getByText(/월간/)).toBeInTheDocument();
  });
});
