"""Stat tiles — the dashboard KPI row (web kit ``.stat`` translated).

Surface + 3px left rail via QSS (``mgfClass="statTile"``, optional
``mgfAccent="true"`` promoting the rail to gold — at most one per
view). Value in mono semibold for tabular alignment; label as a mono
micro-eyebrow.
"""

from __future__ import annotations

from PySide6.QtWidgets import QFrame, QLabel, QVBoxLayout, QWidget

from mgf.brand_qt.fonts import mono_font
from mgf.brand_qt.tokens import TEXT_PT, WEIGHT
from mgf.brand_qt.widgets.props import set_mgf


class StatTile(QFrame):
    """One KPI tile: big value + eyebrow label."""

    def __init__(
        self,
        label: str,
        value: str = "—",
        *,
        accent: bool = False,
        parent: QWidget | None = None,
    ) -> None:
        super().__init__(parent)
        layout = QVBoxLayout(self)
        layout.setContentsMargins(16, 12, 20, 12)
        layout.setSpacing(2)
        self._value = QLabel(value, self)
        self._value.setFont(mono_font(18, WEIGHT["semibold"]))
        layout.addWidget(self._value)
        self._label = QLabel(label.upper(), self)
        self._label.setFont(mono_font(TEXT_PT["xs"], WEIGHT["medium"]))
        set_mgf(self._label, Class="statLabel")
        layout.addWidget(self._label)
        set_mgf(self, Class="statTile", Accent="true" if accent else "false")

    def set_value(self, value: str) -> None:
        self._value.setText(value)

    def value(self) -> str:
        return self._value.text()


__all__ = ["StatTile"]
