"""Test harness page for ``render_findings_panel``.

A standalone Streamlit page module the AppTest layer can drive
directly. Renders the findings panel with whatever findings live in
``st.session_state["test_findings"]`` so test code can inject a list
and inspect what's rendered, without having to fake a file_uploader
widget.

Lives next to its test file so it ships with the GUI test layer and
never gets confused with a real page.
"""

from __future__ import annotations

import sys
from pathlib import Path

import streamlit as st

# Same sys.path bootstrap as the real pages so ``src.*`` imports work
# regardless of how AppTest invokes the script.
_project_root = Path(__file__).resolve().parent.parent.parent
if str(_project_root) not in sys.path:
    sys.path.insert(0, str(_project_root))


# ``st.page_link`` requires a multipage-app context (Streamlit looks up
# the target page's URL from the app's PagesManager). AppTest doesn't
# wire that up for a standalone page, so any ``page_link`` call raises
# ``KeyError: 'url_pathname'`` here. We swap it for a markdown stub
# that renders the label inline — same observable text, no nav, no
# crash.
def _page_link_stub(page: str, *, label: str, **_kwargs) -> None:
    st.markdown(f"[{label}]")

st.page_link = _page_link_stub  # type: ignore[assignment]

from src.gui.components import hide_streamlit_chrome, render_findings_panel

st.set_page_config(page_title="findings test", page_icon="🧪", layout="wide")
hide_streamlit_chrome()

findings = st.session_state.get("test_findings", [])
render_findings_panel(findings)
