from pathlib import Path


def test_runtime_uses_bottom_command_dock_with_user_tabs():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    html = Path("ui_builder/static/index.html").read_text(encoding="utf-8")
    css = Path("ui_builder/static/styles.css").read_text(encoding="utf-8")
    assert 'id="runtimeButtonDock"' in html
    assert "function renderHockeyQuickCommandDock" in js
    assert 'data-quick-command-tab' in js
    assert 'data-quick-command-button' in js
    assert '>+ Вкладка</button>' in js
    assert 'Название вкладки' in js
    assert '.runtime-button-dock' in css
    assert '.quick-command-button.is-on-air' in css


def test_legacy_prematch_tab_is_removed_but_button_data_is_preserved():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    assert 'filter((tab) => tab?.id !== "prematch")' in js
    assert 'component?.type !== "hockey_prematch_panel"' in js
    assert 'state.config.prematch_buttons = normalizePrematchButtons' in js
    assert 'state.config.prematch_groups = normalizePrematchGroups' in js


def test_button_and_keyboard_success_use_toasts_not_per_button_timestamps():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    assert 'toast(`Выполнено: ${sequence.name} · кнопка «${meta.button_label || sequence.name}»`)' in js
    assert 'toast(`Шорткат выполнен: ${sequence.name}`)' in js
    assert 'const shortcutSuccessToast = () => toast(`Шорткат выполнен:' in js
    assert 'prematchButtonRuntimeStatus' not in js
    assert 'data-prematch-runtime-status' not in js
    assert '✓ ${entry.time}' not in js


def test_overlay_ack_tracking_controls_button_on_air_highlight():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    assert "function trackRuntimeOverlayCommands" in js
    assert "function shortcutSequenceIsOnAir" in js
    assert 'trackRuntimeOverlayCommands(clean, execution)' in js
    assert 'node.classList.toggle("is-on-air"' in js
    assert 'state.vmixOverlayRuntime.clear()' in js
    assert 'state.vmixOverlayRuntime.delete(String(layer))' in js


def test_operator_shortcut_list_only_contains_real_key_combinations():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    assert '.filter((sequence) => sequence.enabled && sequence.combo)' in js
    assert '.filter((shortcut) => shortcut.enabled && shortcut.combo)' in js
    assert 'filter((item) => item.enabled !== false && normalizeShortcutCombo(item.combo))' in js


def test_button_limit_is_increased_for_bottom_panel():
    js = Path("ui_builder/static/app.js").read_text(encoding="utf-8")
    manager = Path("ui_builder/manager.py").read_text(encoding="utf-8")
    assert 'source.slice(0, 64)' in js
    assert 'draft.length >= 64' in js
    assert 'raw_prematch_buttons[:64]' in manager
