import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';

// Mock @inertiajs/react Link to avoid Inertia context requirement
vi.mock('@inertiajs/react', async () => {
  const actual = await vi.importActual('@inertiajs/react');
  return {
    ...actual,
    Link: ({ href, children }: { href: string; children: React.ReactNode }) => (
      <a href={href}>{children}</a>
    ),
  };
});

import React from 'react';

import ActivationPromptCard from './ActivationPromptCard';

describe('ActivationPromptCard', () => {
  const baseProps = { siteId: 1, siteName: 'Test Site' };

  it('renders connect_gsc variant without error', () => {
    render(<ActivationPromptCard variant="connect_gsc" {...baseProps} />);
    // Title and CTA both have this text
    const matches = screen.getAllByText('Connect Google Search Console');
    expect(matches.length).toBeGreaterThanOrEqual(1);
  });

  it('renders gsc_syncing variant without error', () => {
    render(<ActivationPromptCard variant="gsc_syncing" {...baseProps} />);
    expect(screen.getByText('Syncing your data…')).toBeInTheDocument();
  });

  it('renders run_analysis variant without error', () => {
    render(<ActivationPromptCard variant="run_analysis" {...baseProps} />);
    // Title and CTA both have "Run your first analysis" text
    const matches = screen.getAllByText('Run your first analysis');
    expect(matches.length).toBeGreaterThanOrEqual(1);
  });

  it('gsc_syncing CTA button is disabled', () => {
    render(<ActivationPromptCard variant="gsc_syncing" {...baseProps} />);
    const button = screen.getByRole('button', { name: /syncing in progress/i });
    expect(button).toBeDisabled();
  });

  it('connect_gsc CTA renders as a link', () => {
    render(<ActivationPromptCard variant="connect_gsc" {...baseProps} />);
    const links = screen.getAllByRole('link');
    expect(links.length).toBeGreaterThanOrEqual(1);
  });

  it('run_analysis CTA renders as a link', () => {
    render(<ActivationPromptCard variant="run_analysis" {...baseProps} />);
    // Link has "Run your first analysis" text (may appear multiple times including title)
    const links = screen.getAllByRole('link');
    expect(links.length).toBeGreaterThanOrEqual(1);
  });

  it('displays site name', () => {
    render(<ActivationPromptCard variant="connect_gsc" {...baseProps} siteName="My SEO Site" />);
    expect(screen.getByText('My SEO Site')).toBeInTheDocument();
  });
});
