# app/src/telegram/ui/common.py

from __future__ import annotations

from datetime import datetime
from zoneinfo import ZoneInfo

from src.core.config import load_settings
from src.core.system_status import get_runtime_mode_label


def mode_line() -> str:
    label = get_runtime_mode_label()
    return f"🔸 <b>{label}</b>\n\n"


def breadcrumb_line(*items: str) -> str:
    if not items:
        return ""
        
    first = items[0].upper()
    rest = " · ".join(items[1:])

    if rest:
        return f"<b>{first}</b> · {rest}\n\n"

    return f"<b>{first}</b>\n\n"


def screen_header(
    *,
    title: str,
    path: list[str] | None = None,
    show_mode: bool = False,
) -> str:
    parts: list[str] = [f"<b>{title}</b>"]

    if show_mode:
        parts.append(f"🔸 <b>{get_runtime_mode_label()}</b>")

    if path:
        parts.append(f"<b>{' → '.join(path).upper()}</b>")

    return "\n".join(parts) + "\n\n"


def now_line() -> str:
    settings = load_settings()
    tz_name = settings.tz or "UTC"

    try:
        local_dt = datetime.now(ZoneInfo(tz_name))
    except Exception:
        local_dt = datetime.utcnow()

    return f"<i>Обновлено: {local_dt.strftime('%H:%M:%S')}</i>"