import { describe, expect, it } from 'vitest'
import { APPROVED_BASELINE_MENU_KEYS, hasRenderableMenuItems, shouldUseGeneratedMenu } from './Sidebar'

describe('Sidebar menu rendering helpers', () => {
  it('keeps the safe fallback menu to the approved seven baseline items in order', () => {
    expect(APPROVED_BASELINE_MENU_KEYS).toEqual([
      'dashboard',
      'reservations',
      'fleet',
      'customers',
      'reports',
      'billing',
      'settings',
    ])
  })

  it('treats an empty employee menu as non-renderable so fallback navigation remains available', () => {
    expect(hasRenderableMenuItems(null)).toBe(false)
    expect(hasRenderableMenuItems([])).toBe(false)
    expect(shouldUseGeneratedMenu('loaded', [])).toBe(false)
    expect(shouldUseGeneratedMenu('loaded', [], 'full')).toBe(false)
    expect(shouldUseGeneratedMenu('loaded', [], 'none')).toBe(true)
  })

  it('ignores structural-only menu responses without clickable entries', () => {
    expect(hasRenderableMenuItems([
      {
        id: 'section',
        systemKey: null,
        label: 'Workspace',
        itemType: 'SECTION_LABEL',
        routeOrUrl: null,
        icon: null,
        parentId: null,
        openInNewTab: false,
        displayOrder: 1,
        children: [],
      },
      {
        id: 'divider',
        systemKey: null,
        label: '',
        itemType: 'DIVIDER',
        routeOrUrl: null,
        icon: null,
        parentId: null,
        openInNewTab: false,
        displayOrder: 2,
        children: [],
      },
    ])).toBe(false)
  })

  it('detects nested clickable menu entries', () => {
    const menuItems = [
      {
        id: 'parent',
        systemKey: null,
        label: 'Operations',
        itemType: 'PARENT_MENU' as const,
        routeOrUrl: null,
        icon: null,
        parentId: null,
        openInNewTab: false,
        displayOrder: 1,
        children: [
          {
            id: 'fleet',
            systemKey: 'fleet',
            label: 'Fleet',
            itemType: 'INTERNAL_PAGE' as const,
            routeOrUrl: '/fleet',
            icon: 'Car',
            parentId: 'parent',
            openInNewTab: false,
            displayOrder: 1,
            children: [],
          },
        ],
      },
    ]

    expect(hasRenderableMenuItems(menuItems)).toBe(true)
    expect(shouldUseGeneratedMenu('loaded', menuItems)).toBe(true)
    expect(shouldUseGeneratedMenu('failed', menuItems)).toBe(false)
  })
})
