/**
 * (share/layout/end-user/header/list-items — pathname-based active link).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'
import { EUHeaderListItems } from '../list-items'

const mockUsePathname = jest.fn()
const mockTranslate = Object.assign((key: string) => `translated:${key}`, {
  has: (key: string) => key === 'apiproducts',
})

jest.mock('@/i18n/navigation', () => ({
  Link: ({ children, href }: any) => <a href={href}>{children}</a>,
  usePathname: () => mockUsePathname(),
}))
jest.mock('next-intl', () => ({
  useTranslations: () => mockTranslate,
}))
jest.mock('@/share/ui/navigation-menu', () => ({
  NavigationMenu: ({ children }: any) => <nav>{children}</nav>,
  NavigationMenuList: ({ children }: any) => <ul>{children}</ul>,
  NavigationMenuItem: ({ children }: any) => <li>{children}</li>,
  NavigationMenuLink: ({ children, asChild, ...props }: any) => <span {...props}>{children}</span>,
  navigationMenuTriggerStyle: () => '',
}))

describe('[share/layout/end-user/header/list-items]', () => {
  beforeEach(() => {
    mockUsePathname.mockReturnValue('/api-products/detail')
  })

  describe('EUHeaderListItems', () => {
    it('renders translated labels and marks active item from pathname prefix', () => {
      render(<EUHeaderListItems />)

      expect(screen.getByText('translated:apiproducts')).toBeInTheDocument()
      expect(screen.getByText('news')).toBeInTheDocument()
      expect(screen.getByText('support')).toBeInTheDocument()
      expect(screen.getByText('translated:apiproducts').closest('span')).toHaveAttribute(
        'data-active',
        'true'
      )
    })
  })
})
