// @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: {
    retryAllFailed: vi.fn(async () => {})
  }
}));

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

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

  it('renders nothing when ai_enabled=false (even with failedCount > 0)', () => {
    useInbox.setState({
      ai_enabled: false,
      failedCount: 3
    } as Partial<ReturnType<typeof useInbox.getState>>);
    const { container } = render(<FailedBanner />);
    expect(container).toBeEmptyDOMElement();
  });

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

  it('renders banner when ai_enabled=true and failedCount > 0', () => {
    useInbox.setState({
      ai_enabled: true,
      failedCount: 5
    } as Partial<ReturnType<typeof useInbox.getState>>);
    const { container } = render(<FailedBanner />);
    expect(container).not.toBeEmptyDOMElement();
  });
});
