import assert from 'node:assert/strict'

import {
  appViews,
  navItems,
  resolveAppViewFromRoute,
  resolveTargetRouteName
} from '../src/composables/useNavigation.js'

function testDerivesViewFromRouteName() {
  assert.equal(resolveAppViewFromRoute({ name: 'app-log-detail', meta: {} }), 'logs')
  assert.equal(resolveAppViewFromRoute({ name: 'app-request-detail', meta: {} }), 'documents')
  assert.equal(resolveAppViewFromRoute({ name: 'app-policies', meta: { appView: 'logs' } }), 'policies')
}

function testFallsBackToValidMeta() {
  assert.equal(resolveAppViewFromRoute({ name: 'custom', meta: { appView: 'employees' } }), 'employees')
  assert.equal(resolveAppViewFromRoute({ name: 'custom', meta: { appView: 'unknown' } }), 'overview')
}

function testResolvesMainRouteNames() {
  assert.equal(resolveTargetRouteName('logs'), 'app-logs')
  assert.equal(resolveTargetRouteName('policies'), 'app-policies')
  assert.equal(resolveTargetRouteName('requests'), 'app-overview')
  assert.equal(resolveTargetRouteName('approval'), 'app-overview')
  assert.equal(resolveTargetRouteName('archive'), 'app-overview')
  assert.equal(resolveTargetRouteName('missing'), 'app-overview')
}

function testLegacyCentersAreRemovedFromNavigation() {
  assert.equal(appViews.includes('requests'), false)
  assert.equal(appViews.includes('approval'), false)
  assert.equal(appViews.includes('archive'), false)
  assert.equal(navItems.some((item) => ['requests', 'approval', 'archive'].includes(item.id)), false)
}

function run() {
  testDerivesViewFromRouteName()
  testFallsBackToValidMeta()
  testResolvesMainRouteNames()
  testLegacyCentersAreRemovedFromNavigation()
  console.log('navigation route resolution tests passed')
}

run()
