"""Accessibility — Lesbarkeit und Bewegung (gsettings, user-level)."""
from __future__ import annotations

import gi

gi.require_version("Adw", "1")
from gi.repository import Adw, Gtk  # noqa: E402

from taninux.core import accessibility as a11y


def _switch(title: str, subtitle: str, getter, setter) -> Adw.SwitchRow:
    row = Adw.SwitchRow(title=title, subtitle=subtitle)
    row.set_active(getter())
    row.connect("notify::active", lambda r, _p: setter(r.get_active()))
    return row


def build() -> Gtk.Widget:
    page = Adw.PreferencesPage()

    g_see = Adw.PreferencesGroup(title="Seeing")
    g_see.add(_switch("Large text", "Increase the size of text",
                      a11y.large_text, a11y.set_large_text))
    g_see.add(_switch("High contrast", "Make windows and buttons stand out",
                      a11y.high_contrast, a11y.set_high_contrast))
    page.add(g_see)

    g_motion = Adw.PreferencesGroup(title="Motion")
    g_motion.add(_switch("Reduce animations", "Minimise motion across the system",
                         lambda: not a11y.animations(),
                         lambda on: a11y.set_animations(not on)))
    page.add(g_motion)

    return page
