"""The kit's one confirm dialog — action-named buttons, Cancel holds.

Promoted from consumer duplication (PAPER-04): vm-vmanager-app built
``confirm_action`` app-locally on the kit's danger variant while
hrb-app still asked "Yes | Cancel" on hardware-unbinding operations —
two behaviours under one brand. The house rules this encodes:

- the affirmative button says the VERB ("Force detach", never "Yes");
- Cancel is the default AND the escape route — walking away is free;
- a destructive verb carries ``mgfVariant="danger"``.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from PySide6.QtWidgets import QMessageBox

from mgf.brand_qt.widgets.props import set_mgf

if TYPE_CHECKING:
    from PySide6.QtWidgets import QWidget


def confirm_action(
    parent: QWidget | None,
    *,
    title: str,
    text: str,
    action_text: str,
    danger: bool = False,
    cancel_text: str = "Cancel",
    informative: str | None = None,
) -> bool:
    """Ask before acting; True only when the operator chose the verb.

    ``action_text`` is the verb button ("Force detach", "Erase device");
    ``danger=True`` paints it in the danger variant. Cancel keeps both
    the default and the Escape role, so Enter-mashing and Esc both walk
    away. ``informative`` fills the smaller detail line under ``text``.
    """
    box = QMessageBox(parent)
    box.setIcon(QMessageBox.Icon.Warning if danger else QMessageBox.Icon.Question)
    box.setWindowTitle(title)
    box.setText(text)
    if informative is not None:
        box.setInformativeText(informative)
    action = box.addButton(action_text, QMessageBox.ButtonRole.AcceptRole)
    cancel = box.addButton(cancel_text, QMessageBox.ButtonRole.RejectRole)
    box.setDefaultButton(cancel)
    box.setEscapeButton(cancel)
    if danger:
        set_mgf(action, Variant="danger")
    box.exec()
    return box.clickedButton() is action


__all__ = ["confirm_action"]
