"""Tests for HNav and VNav navigation components."""

import uframe


# ---------------------------------------------------------------------------
# HNav — Horizontal Navigation
# ---------------------------------------------------------------------------


def test_hnav_bar():
    source = '''page "Test" 60
  hnav bar
    item "Home" "/page/index.mu" active
    item "About" "/page/about.mu"
    item "Settings" "/page/settings.mu"'''
    result = uframe.compile(source)
    assert "Home" in result.ascii
    assert "About" in result.ascii
    assert "Settings" in result.ascii
    # Bar style has borders
    assert "┌" in result.ascii or "─" in result.ascii


def test_hnav_tabs():
    source = '''page "Test" 60
  hnav tabs
    item "Dashboard" "/page/dash.mu" active
    item "Logs" "/page/logs.mu"'''
    result = uframe.compile(source)
    assert "Dashboard" in result.ascii
    assert "Logs" in result.ascii


def test_hnav_pills():
    source = '''page "Test" 60
  hnav pills
    item "All" "/page/all.mu" active
    item "Active" "/page/active.mu"
    item "Stale" "/page/stale.mu"'''
    result = uframe.compile(source)
    assert "All" in result.ascii
    assert "Active" in result.ascii
    assert "Stale" in result.ascii


def test_hnav_breadcrumb():
    source = '''page "Test" 60
  hnav breadcrumb
    item "Home" "/page/index.mu"
    item "Network" "/page/network.mu"
    item "Node Alpha" "/page/alpha.mu" active'''
    result = uframe.compile(source)
    assert "Home" in result.ascii
    assert "Network" in result.ascii
    assert "Node Alpha" in result.ascii
    # Breadcrumb uses ▸ separator
    assert "▸" in result.ascii


def test_hnav_underline():
    source = '''page "Test" 60
  hnav underline
    item "Overview" "/page/overview.mu" active
    item "Details" "/page/details.mu"'''
    result = uframe.compile(source)
    assert "Overview" in result.ascii
    assert "Details" in result.ascii
    # Active item has underline
    assert "━" in result.ascii


def test_hnav_with_separator():
    source = '''page "Test" 60
  hnav bar
    item "Home" "/page/index.mu" active
    separator
    item "Help" "/page/help.mu"'''
    result = uframe.compile(source)
    assert "Home" in result.ascii
    assert "Help" in result.ascii


def test_hnav_micron_links():
    source = '''page "Test" 60
  hnav bar
    item "Home" "/page/index.mu"
    item "About" "/page/about.mu"'''
    result = uframe.compile(source)
    assert "index.mu" in result.micron
    assert "about.mu" in result.micron


# ---------------------------------------------------------------------------
# VNav — Vertical Navigation
# ---------------------------------------------------------------------------


def test_vnav_list():
    source = '''page "Test" 60
  vnav list
    item "Dashboard" "/page/dash.mu" active
    item "Peers" "/page/peers.mu"
    item "Routes" "/page/routes.mu"'''
    result = uframe.compile(source)
    assert "Dashboard" in result.ascii
    assert "Peers" in result.ascii
    assert "Routes" in result.ascii
    # Active item has marker
    assert "▸" in result.ascii


def test_vnav_boxed():
    source = '''page "Test" 60
  vnav boxed
    item "Home" "/page/index.mu" active
    item "Settings" "/page/settings.mu"'''
    result = uframe.compile(source)
    assert "Home" in result.ascii
    assert "Settings" in result.ascii
    # Boxed style has borders
    assert "┌" in result.ascii
    assert "└" in result.ascii


def test_vnav_tree():
    source = '''page "Test" 60
  vnav tree
    item "Root" "/page/root.mu" active
    item "Child A" "/page/a.mu"
    item "Child B" "/page/b.mu"'''
    result = uframe.compile(source)
    assert "Root" in result.ascii
    assert "Child A" in result.ascii
    assert "Child B" in result.ascii
    # Tree style has connectors
    assert "├" in result.ascii or "└" in result.ascii


def test_vnav_sidebar():
    source = '''page "Test" 60
  vnav sidebar
    item "Overview" "/page/overview.mu" active
    item "Metrics" "/page/metrics.mu"
    item "Alerts" "/page/alerts.mu"'''
    result = uframe.compile(source)
    assert "Overview" in result.ascii
    assert "Metrics" in result.ascii
    assert "Alerts" in result.ascii


def test_vnav_minimal():
    source = '''page "Test" 60
  vnav minimal
    item "Page 1" "/page/1.mu"
    item "Page 2" "/page/2.mu" active
    item "Page 3" "/page/3.mu"'''
    result = uframe.compile(source)
    assert "Page 1" in result.ascii
    assert "Page 2" in result.ascii
    assert "Page 3" in result.ascii


def test_vnav_with_separator():
    source = '''page "Test" 60
  vnav list
    item "Home" "/page/index.mu" active
    separator
    item "Help" "/page/help.mu"'''
    result = uframe.compile(source)
    assert "Home" in result.ascii
    assert "Help" in result.ascii
    assert "─" in result.ascii


def test_vnav_with_width():
    source = '''page "Test" 60
  vnav boxed 25
    item "Nav Item" "/page/nav.mu" active'''
    result = uframe.compile(source)
    assert "Nav Item" in result.ascii


def test_vnav_micron_links():
    source = '''page "Test" 60
  vnav list
    item "Home" "/page/index.mu"
    item "About" "/page/about.mu"'''
    result = uframe.compile(source)
    assert "index.mu" in result.micron
    assert "about.mu" in result.micron
