"""Human-first implementation-direction comparison view."""
from __future__ import annotations

from ..common import evidence_index
from ..models import HumanReportView


def build_implementation_option_selection_view(data: dict) -> HumanReportView:
    selection = data["implementationOptionSelection"]
    context = {
        "humanSummary": data["humanSummary"],
        "selection": selection,
        "directionSelection": (
            selection if selection["mode"] == "candidate-comparison" else None
        ),
        "narrative": selection["userNarrative"],
        "recommendedOption": next(
            (
                option
                for option in selection["rankedOptions"]
                if option["id"] == selection["recommendedOptionId"]
            ),
            None,
        ),
        "evidenceIndex": evidence_index(data),
    }
    return HumanReportView(
        task_type="implementation-option-selection",
        template_name="html/tasks/implementation-option-selection.template.html",
        context=context,
        figures=(),
    )
