import { describe, test, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { Header } from './header'

describe('Header', () => {
  const mockLabels = {
    title: 'Basemap Selection',
    actions: {
      close: 'Close Panel',
    },
  }

  const mockOnChangeCollapsed = vi.fn()

  test('should not render title and close button when not mobile', () => {
    render(
      <Header
        isMobile={false}
        labels={mockLabels}
        onChangeCollapsed={mockOnChangeCollapsed}
      />,
    )

    expect(screen.queryByText(mockLabels.title)).toBeNull()
    expect(screen.queryByLabelText(mockLabels.actions.close)).toBeNull()
  })

  test('should render title and close button when mobile', () => {
    render(
      <Header
        isMobile={true}
        labels={mockLabels}
        onChangeCollapsed={mockOnChangeCollapsed}
      />,
    )

    expect(screen.getByText(mockLabels.title)).toBeDefined()
    expect(screen.getByLabelText(mockLabels.actions.close)).toBeDefined()
  })

  test('should call onChangeCollapsed when close button is clicked', () => {
    render(
      <Header
        isMobile={true}
        labels={mockLabels}
        onChangeCollapsed={mockOnChangeCollapsed}
      />,
    )

    const closeButton = screen.getByLabelText(mockLabels.actions.close)
    fireEvent.click(closeButton)
    expect(mockOnChangeCollapsed).toHaveBeenCalledTimes(1)
  })
})
