import React from 'react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import ResultsDisplay from '../src/components/ResultsDisplay';
import { Decision } from '../src/hooks/useSession';

// Mock the Clipboard API
Object.defineProperty(navigator, 'clipboard', {
  value: {
    writeText: jest.fn(),
  },
  writable: true,
});

describe('ResultsDisplay responsiveness and touch functionality', () => {
  const mockDecision: Decision = {
    goTo: 'Go-to decision',
    alsoGood: 'Also good decision',
    considerable: 'Considerable decision',
    needsDiscussion: 'Needs discussion decision',
    noGoes: 'No-goes decision',
  };

  beforeEach(() => {
    jest.clearAllMocks();
  });

  it('renders without crashing', () => {
    render(<ResultsDisplay decision={mockDecision} />);
    expect(screen.getByText('Cooperative Decision')).toBeInTheDocument();
  });

  it('should display the Copy Link button', () => {
    render(<ResultsDisplay decision={mockDecision} />);
    expect(screen.getByRole('button', { name: /copy link/i })).toBeInTheDocument();
    expect(screen.getByTestId('ContentCopyIcon')).toBeInTheDocument();
  });

  it('should copy the session URL to clipboard when Copy Link button is clicked', async () => {
    render(<ResultsDisplay decision={mockDecision} />);
    const copyButton = screen.getByRole('button', { name: /copy link/i });
    fireEvent.click(copyButton);

    await waitFor(() => {
      expect(navigator.clipboard.writeText).toHaveBeenCalledTimes(1);
      expect(navigator.clipboard.writeText).toHaveBeenCalledWith(window.location.href);
      expect(screen.getByRole('button', { name: /copied!/i })).toBeInTheDocument();
    });
  });

  // Placeholder for responsive tests
  it('should adapt layout for mobile view', () => {
    // Simulate mobile viewport and check for specific layout changes
  });

  // Placeholder for touch functionality tests
  it('should handle touch events correctly', () => {
    // Simulate touch events and verify component behavior
  });
});
