import { describe, it, expect, vi, beforeEach } from 'vitest'
import { renderWithProviders, screen, waitFor } from '@/lib/test-utils'
import { ComplianceMapping } from '../ComplianceMapping'
import { NetworkTopologyDocs } from '../NetworkTopologyDocs'
import { DeploymentTimeline } from '../DeploymentTimeline'
import { CostEstimates } from '../CostEstimates'

// Mock the data hooks
vi.mock('@/lib/hooks/useInfrastructureData', () => ({
  useCountries: () => ({
    countries: [
      { name: 'Italy', region: 'Europe', relationshipType: 'Full Diplomatic Relations' },
    ],
    loading: false,
    error: null,
  }),
  useNetworkTopologies: () => ({
    topologies: [
      {
        id: '1',
        region: 'Europe',
        entity: 'SMOM',
        nodes: [],
        edges: [],
      },
    ],
    loading: false,
    error: null,
  }),
  useComplianceRequirements: () => ({
    requirements: [
      {
        country: 'Italy',
        region: 'Europe',
        frameworks: ['GDPR'],
        status: 'Compliant',
        requirements: [],
      },
    ],
    loading: false,
    error: null,
  }),
  useDeploymentMilestones: () => ({
    milestones: [],
    loading: false,
    error: null,
  }),
  useCostEstimates: () => ({
    estimates: [],
    loading: false,
    error: null,
  }),
}))

describe('Infrastructure Components Integration', () => {
  beforeEach(() => {
    vi.clearAllMocks()
  })

  describe('ComplianceMapping', () => {
    it('should render and display compliance data', async () => {
      renderWithProviders(<ComplianceMapping />)

      await waitFor(() => {
        expect(screen.getByText(/compliance mapping/i)).toBeInTheDocument()
      })

      expect(screen.getByText('Italy')).toBeInTheDocument()
    })

    it('should handle edit mode toggle', async () => {
      renderWithProviders(<ComplianceMapping />)

      const editToggle = screen.getByRole('button', { name: /edit mode/i })
      expect(editToggle).toBeInTheDocument()
    })
  })

  describe('NetworkTopologyDocs', () => {
    it('should render topology visualization', async () => {
      renderWithProviders(<NetworkTopologyDocs />)

      await waitFor(() => {
        expect(screen.getByText(/network topology/i)).toBeInTheDocument()
      })
    })

    it('should have export buttons', async () => {
      renderWithProviders(<NetworkTopologyDocs />)

      await waitFor(() => {
        expect(screen.getByText(/export png/i)).toBeInTheDocument()
      })
    })
  })

  describe('DeploymentTimeline', () => {
    it('should render timeline view', async () => {
      renderWithProviders(<DeploymentTimeline />)

      await waitFor(() => {
        expect(screen.getByText(/deployment timeline/i)).toBeInTheDocument()
      })
    })
  })

  describe('CostEstimates', () => {
    it('should render cost estimates view', async () => {
      renderWithProviders(<CostEstimates />)

      await waitFor(() => {
        expect(screen.getByText(/cost estimates/i)).toBeInTheDocument()
      })
    })
  })
})

