"""Motion helper tests (offscreen)."""

from __future__ import annotations

import pytest

pytest.importorskip("PySide6")
pytest.importorskip("pytestqt")

from PySide6.QtWidgets import QLabel

from mgf.brand_qt.motion import fade_in

pytestmark = pytest.mark.gui


def test_fade_in_attaches_an_opacity_effect(qtbot) -> None:
    label = QLabel("page")
    qtbot.addWidget(label)
    fade_in(label)
    assert label.graphicsEffect() is not None


def test_fade_in_disabled_is_a_no_op(qtbot) -> None:
    label = QLabel("page")
    qtbot.addWidget(label)
    fade_in(label, enabled=False)
    assert label.graphicsEffect() is None


def test_reduce_motion_policy_gates_fade_in(qtbot) -> None:
    """The kit-level policy the docstring promised now exists (PAPER-02)."""
    from PySide6.QtWidgets import QLabel

    from mgf.brand_qt.motion import fade_in, reduce_motion, set_reduce_motion

    label = QLabel("x")
    qtbot.addWidget(label)
    try:
        set_reduce_motion(True)
        assert reduce_motion() is True
        fade_in(label)  # default defers to policy -> no effect installed
        assert label.graphicsEffect() is None
        fade_in(label, enabled=True)  # explicit override still animates
        assert label.graphicsEffect() is not None
    finally:
        set_reduce_motion(False)
