"""abreka backlog show — full detail view of one backlog item."""

from __future__ import annotations

import click
from rich.console import Console
from rich.panel import Panel

from abreka.config import find_abreka_dir
from abreka.persistence import load_backlog_item, normalize_backlog_id


@click.command("show")
@click.argument("item_id")
def show_cmd(item_id: str):
    """Show full detail view of a backlog item."""
    abreka_dir = find_abreka_dir()
    item_id = normalize_backlog_id(item_id)
    item = load_backlog_item(abreka_dir, item_id)

    console = Console()

    console.print(Panel(
        f"[bold]Backlog {item.id}[/bold]  [{item.status.value}]",
        title="Backlog Item",
    ))

    console.print(f"  [bold]Title:[/bold]      {item.title}")
    console.print(f"  [bold]Status:[/bold]     {item.status.value}")
    console.print(f"  [bold]Priority:[/bold]   {item.priority}")
    console.print(f"  [bold]Created:[/bold]    {item.created_at.isoformat()}")
    console.print(f"  [bold]Updated:[/bold]    {item.updated_at.isoformat()}")
    if item.tags:
        console.print(f"  [bold]Tags:[/bold]       {', '.join(item.tags)}")
    if item.source_exp:
        console.print(f"  [bold]Source Exp:[/bold] {item.source_exp}")
    if item.resolved_exp:
        console.print(f"  [bold]Resolved Exp:[/bold] {item.resolved_exp}")
    console.print()

    if item.description:
        console.print(f"  [bold]Description:[/bold]")
        console.print(f"  {item.description}")
        console.print()

    if item.dismiss_reason:
        console.print(f"  [bold dim]Dismiss reason:[/bold dim] {item.dismiss_reason}")
