/**
 * (tier-specific i18n keys for title/description; scope table delegated to TableView mock).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'
import ViewToken from '../index'

jest.mock('@/i18n/navigation', () => ({
  useRouter: () => ({ push: jest.fn(), back: jest.fn() }),
}))
jest.mock('next-intl', () => ({ useTranslations: () => (k: string) => k }))
jest.mock('@/share/ui/table', () => ({
  Table: ({ children }: any) => <table>{children}</table>,
  TableBody: ({ children }: any) => <tbody>{children}</tbody>,
  TableRow: ({ children }: any) => <tr>{children}</tr>,
  TableCell: ({ children }: any) => <td>{children}</td>,
}))

jest.mock('@/share/components/table/use-app-table', () => ({
  useAppTable: () => ({
    getRowModel: () => ({ rows: [] }),
    getHeaderGroups: () => [],
    getAllColumns: () => [],
  }),
}))

jest.mock('@/share/components/table', () => ({
  TableView: () => <div>TableView</div>,
}))

describe('[components/application/detail/overview/view-token] ViewToken', () => {
  it.each([
    ['SANDBOX', 'SANDBOX'],
    ['PRODUCTION', 'PRODUCTION'],
  ] as const)('shows tier-specific title and description for %s', (tier, keySuffix) => {
    render(<ViewToken tier={tier} scopes={[]} />)
    expect(screen.getByText(`keys.view_token_title.${keySuffix}`)).toBeInTheDocument()
    expect(
      screen.getByText(`keys.view_token_description.${keySuffix}`)
    ).toBeInTheDocument()
  })

  it('renders with scopes (table delegated to mocked TableView)', () => {
    render(<ViewToken tier="SANDBOX" scopes={[{ scope: 's1', value: 'v1' }]} />)
    expect(screen.getByText('keys.view_token_title.SANDBOX')).toBeInTheDocument()
    expect(
      screen.getByText('keys.view_token_description.SANDBOX')
    ).toBeInTheDocument()
  })
})
