/**
 * (empty vs hydrated certificate branch).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'

jest.mock('next-intl', () => ({
  useTranslations: () => (k: string) => k,
}))

jest.mock('@/share/components/empty-state', () => ({
  __esModule: true,
  default: ({ title }: { title: string }) => (
    <div data-testid="empty-state">{title}</div>
  ),
}))

jest.mock('../view', () => ({
  CertificateView: ({ cert_id }: { cert_id: string }) => (
    <div data-testid="cert-view">{cert_id}</div>
  ),
}))

import TryoutCertificate from '../index'

const certificateStub = {
  id: 'cert-99',
  certificateNumber: 'n',
  scenarioName: 's',
  apiName: 'a',
  apiId: 'api-1',
  applicationId: 'app-1',
  issueDate: '2024-01-01',
  status: 'ACTIVE' as const,
}

describe('[components/api-product/tryout/certificate] TryoutCertificate', () => {
  describe('negative / empty dataset', () => {
    it.each<{ label: string; certificate: null | undefined }>([
      { label: 'null', certificate: null },
      { label: 'undefined', certificate: undefined },
    ])('renders EmptyState when certificate prop is $label', ({ certificate }) => {
      render(<TryoutCertificate certificate={certificate} />)
      expect(screen.getByTestId('empty-state')).toBeInTheDocument()
      expect(screen.getByText('empty.certificate.title')).toBeInTheDocument()
      expect(screen.queryByTestId('cert-view')).not.toBeInTheDocument()
    })
  })

  describe('happy path', () => {
    it('delegates into CertificateView with cert id', () => {
      render(<TryoutCertificate certificate={certificateStub} />)
      expect(screen.getByTestId('cert-view')).toHaveTextContent('cert-99')
    })
  })
})
