"""HTML page routes served via Jinja2 templates."""

from __future__ import annotations

from fastapi import APIRouter, Request
from fastapi.templating import Jinja2Templates

router = APIRouter()
templates = Jinja2Templates(directory="backend/templates")


def _ctx(request: Request, page: str, **extra) -> dict:
    return {"request": request, "active_page": page, **extra}


@router.get("/")
async def overview(request: Request):
    return templates.TemplateResponse("overview.html", _ctx(request, "overview"))


@router.get("/detections")
async def detections(request: Request):
    return templates.TemplateResponse("detections.html", _ctx(request, "detections"))


@router.get("/scores")
async def scores(request: Request):
    return templates.TemplateResponse("scores.html", _ctx(request, "scores"))


@router.get("/traffic")
async def traffic(request: Request):
    return templates.TemplateResponse("traffic.html", _ctx(request, "traffic"))


@router.get("/ip/{ip}")
async def ip_detail(request: Request, ip: str):
    return templates.TemplateResponse("ip_detail.html", _ctx(request, "ip_detail", ip=ip))


@router.get("/classify")
async def classify(request: Request):
    return templates.TemplateResponse("classify.html", _ctx(request, "classify"))


@router.get("/features")
async def features(request: Request):
    return templates.TemplateResponse("features.html", _ctx(request, "features"))


@router.get("/models")
async def models(request: Request):
    return templates.TemplateResponse("models.html", _ctx(request, "models"))


@router.get("/network")
async def network(request: Request):
    return templates.TemplateResponse("network.html", _ctx(request, "network"))


@router.get("/campaigns")
async def campaigns_page(request: Request):
    return templates.TemplateResponse("campaigns.html", _ctx(request, "campaigns"))


@router.get("/ja4/{fingerprint:path}")
async def ja4_detail_page(request: Request, fingerprint: str):
    return templates.TemplateResponse("ja4_detail.html", _ctx(request, "ja4_detail", ja4=fingerprint))


@router.get("/cluster/{cid}")
async def cluster_detail_page(request: Request, cid: int):
    return templates.TemplateResponse("cluster_detail.html", _ctx(request, "cluster_detail", cid=cid))


@router.get("/tactics")
async def tactics_page(request: Request):
    return templates.TemplateResponse("tactics.html", _ctx(request, "tactics"))


@router.get("/reflists")
async def reflists_page(request: Request):
    return templates.TemplateResponse("reflists.html", _ctx(request, "reflists"))


@router.get("/fleet")
async def fleet_page(request: Request):
    return templates.TemplateResponse("fleet.html", _ctx(request, "fleet"))


@router.get("/health")
async def health_page(request: Request):
    return templates.TemplateResponse("health.html", _ctx(request, "health"))


@router.get("/browsers")
async def browsers_page(request: Request):
    return templates.TemplateResponse("browsers.html", _ctx(request, "browsers"))


@router.get("/fingerprints")
async def fingerprints_page(request: Request):
    return templates.TemplateResponse("fingerprints.html", _ctx(request, "fingerprints"))
