"""Summary cards for document info, segments stats, and source info"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/components/verification_summary.ipynb.

# %% auto #0
__all__ = ['render_document_section', 'render_segments_section', 'render_sources_section', 'render_verification_summary']

# %% ../../nbs/components/verification_summary.ipynb #verify-summary-exports
from typing import Any, List

from fasthtml.common import Div, Span, H3

# DaisyUI components
from cjm_fasthtml_daisyui.components.data_display.card import card_body, card_title
from cjm_fasthtml_daisyui.utilities.semantic_colors import text_dui

# Tailwind utilities
from cjm_fasthtml_tailwind.utilities.spacing import p, m
from cjm_fasthtml_tailwind.utilities.sizing import w, min_w
from cjm_fasthtml_tailwind.utilities.typography import font_size, font_weight, text_align
from cjm_fasthtml_tailwind.utilities.flexbox_and_grid import (
    flex_display, flex_direction, flex, justify, items, gap, flex_wrap
)
from cjm_fasthtml_tailwind.core.base import combine_classes

# Lucide icons via factory
from cjm_fasthtml_lucide_icons.factory import lucide_icon

# Design system recipes (V10 P1 dashboard_tile)
from cjm_fasthtml_design_system.panels import panels

# Local imports
from ..html_ids import VerifyHtmlIds
from ..models import VerificationResult
from ..utils import format_duration_mmss, format_duration_seconds

# %% ../../nbs/components/verification_summary.ipynb #verify-summary-helpers
def _render_stat_row(
    label:str,  # Label text
    value:str,  # Value text
) -> Any:  # Stat row element
    """Render a label-value row for summary display."""
    return Div(
        Span(label, cls=combine_classes(text_dui.base_content.opacity(70), font_size.sm)),
        Span(value, cls=combine_classes(font_weight.medium)),
        cls=combine_classes(flex_display, justify.between, items.center, p.y(1))
    )

def _render_section_header(
    icon:Any,  # Lucide icon component
    title:str,  # Section title
) -> Any:  # Section header element
    """Render a section header with icon."""
    return Div(
        icon,
        H3(title, cls=combine_classes(font_size.lg, font_weight.semibold)),
        cls=combine_classes(flex_display, items.center, gap(2), m.b(3))
    )

# %% ../../nbs/components/verification_summary.ipynb #verify-summary-document
def render_document_section(
    result:VerificationResult,  # Verification result with document info
) -> Any:  # Document info card
    """Render the document info section."""
    # Truncate document ID for display
    doc_id_display = result.document_id[:12] + "..." if len(result.document_id) > 15 else result.document_id
    
    return Div(
        Div(
            _render_section_header(lucide_icon("file-text", size=5), "Document"),
            _render_stat_row("Title", result.document_title),
            _render_stat_row("Media Type", result.document_media_type),
            _render_stat_row("ID", doc_id_display),
            cls=str(card_body)
        ),
        id=VerifyHtmlIds.DOCUMENT_SECTION,
        cls=combine_classes(
            panels.dashboard_tile,
            flex._1, min_w('280px')
        )
    )

# %% ../../nbs/components/verification_summary.ipynb #verify-summary-segments
def render_segments_section(
    result:VerificationResult,  # Verification result with segment stats
) -> Any:  # Segments stats card
    """Render the segments statistics section."""
    return Div(
        Div(
            _render_section_header(lucide_icon("list", size=5), "Segments"),
            _render_stat_row("Count", str(result.segment_count)),
            _render_stat_row("Total Duration", format_duration_mmss(result.total_duration)),
            _render_stat_row("Average", format_duration_seconds(result.avg_segment_duration)),
            cls=str(card_body)
        ),
        id=VerifyHtmlIds.SEGMENTS_SECTION,
        cls=combine_classes(
            panels.dashboard_tile,
            flex._1, min_w('280px')
        )
    )

# %% ../../nbs/components/verification_summary.ipynb #verify-summary-sources
def render_sources_section(
    result:VerificationResult,  # Verification result with source info
) -> Any:  # Sources info card
    """Render the source traceability section."""
    plugins_display = ", ".join(result.source_plugins) if result.source_plugins else "None"
    
    return Div(
        Div(
            _render_section_header(lucide_icon("database", size=5), "Source Traceability"),
            _render_stat_row("Plugin(s)", plugins_display),
            cls=str(card_body)
        ),
        id=VerifyHtmlIds.SOURCES_SECTION,
        cls=combine_classes(
            panels.dashboard_tile,
            flex._1, min_w('280px')
        )
    )

# %% ../../nbs/components/verification_summary.ipynb #verify-summary-grid
def render_verification_summary(
    result:VerificationResult,  # Verification result to display
) -> Any:  # Summary section with all info cards
    """Render the full verification summary with document, segments, and sources."""
    return Div(
        render_document_section(result),
        render_segments_section(result),
        render_sources_section(result),
        cls=combine_classes(flex_display, flex_wrap.wrap, gap(4))
    )
