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

vi.mock('../../src/renderer/inbox/api.js', () => ({
  inboxApi: {
    ollamaRecheck: vi.fn(async () => ({ ok: true }))
  }
}));

import { OllamaBanner } from '../../src/renderer/inbox/components/OllamaBanner';
import { useInbox } from '../../src/renderer/inbox/store';

describe('OllamaBanner — ai_enabled (v0.2.9 Cut B Task 14)', () => {
  beforeEach(() => {
    cleanup();
  });

  it('renders nothing when ai_enabled=false (even if ollama unreachable)', () => {
    useInbox.setState({
      ai_enabled: false,
      ollamaStatus: { ok: false, reason: 'unreachable' }
    } as Partial<ReturnType<typeof useInbox.getState>>);
    const { container } = render(<OllamaBanner />);
    expect(container).toBeEmptyDOMElement();
  });

  it('renders nothing when ai_enabled=true and ollama ok', () => {
    useInbox.setState({
      ai_enabled: true,
      ollamaStatus: { ok: true }
    } as Partial<ReturnType<typeof useInbox.getState>>);
    const { container } = render(<OllamaBanner />);
    expect(container).toBeEmptyDOMElement();
  });

  it('renders banner when ai_enabled=true and ollama not ok', () => {
    useInbox.setState({
      ai_enabled: true,
      ollamaStatus: { ok: false, reason: 'unreachable' }
    } as Partial<ReturnType<typeof useInbox.getState>>);
    const { container } = render(<OllamaBanner />);
    expect(container).not.toBeEmptyDOMElement();
  });
});
