"""Seiten-Registry fürs GTK-Frontend.

Seiten sind in logische SECTIONS gruppiert (Sidebar zeigt Überschriften).
PAGES ist die flache Ableitung (für Stack-Lookup / Navigation).
Neue Seite = Modul in pages/ mit build() + Eintrag in einer Section unten.
"""
from __future__ import annotations

from dataclasses import dataclass
from typing import Callable

from gi.repository import Gtk

from taninux.gui.pages import (
    about,
    accessibility,
    audio,
    backup,
    bluetooth,
    bundles,
    dashboard,
    defaultapps,
    display,
    firewall,
    hub_home,
    kernel,
    locale,
    lock,
    maintain,
    network,
    panel,
    power,
    printers,
    settings,
    shares,
    storage,
    store,
    update,
    users,
    vpn,
)


@dataclass(frozen=True)
class Page:
    key: str
    label: str
    icon: str
    build: Callable[[], Gtk.Widget]
    keywords: tuple[str, ...] = ()


@dataclass(frozen=True)
class Section:
    title: str | None   # None = keine Überschrift (Home)
    pages: list[Page]


# -- System Settings — Hardware/System/Personalisierung --------------------
SETTINGS_SECTIONS: list[Section] = [
    Section(None, [
        Page("dashboard", "Dashboard", "go-home-symbolic", dashboard.build,
             ("overview", "status", "summary", "system", "home")),
    ]),
    Section("System", [
        Page("about", "About", "help-about-symbolic", about.build,
             ("about", "system", "info", "version", "hardware", "cpu", "memory")),
        Page("kernel", "Kernel", "application-x-firmware-symbolic", kernel.build,
             ("kernel", "boot", "bootloader", "lts", "prune", "headers")),
        Page("backup", "Timeshift", "drive-multidisk-symbolic", backup.build,
             ("backup", "backups", "snapshot", "timeshift", "restore", "btrfs")),
        Page("storage", "Storage", "drive-harddisk-symbolic", storage.build,
             ("storage", "disk", "drive", "mount", "usb", "space", "eject")),
        Page("users", "Users", "system-users-symbolic", users.build,
             ("users", "account", "password", "login", "name")),
        Page("defaultapps", "Default Apps", "emblem-default-symbolic", defaultapps.build,
             ("default", "apps", "browser", "mail", "open with", "associations")),
    ]),
    Section("Connectivity", [
        Page("network", "Network", "network-wireless-symbolic", network.build,
             ("network", "wifi", "wi-fi", "internet", "connection", "ethernet")),
        Page("vpn", "VPN", "network-vpn-symbolic", vpn.build,
             ("vpn", "wireguard", "openvpn", "dns", "privacy", "tunnel")),
        Page("bluetooth", "Bluetooth", "bluetooth-symbolic", bluetooth.build,
             ("bluetooth", "pair", "devices", "headset")),
        Page("shares", "Network Shares", "folder-remote-symbolic", shares.build,
             ("shares", "smb", "samba", "sftp", "ftp", "webdav", "nextcloud",
              "nfs", "mount", "nautilus", "cloud")),
    ]),
    Section("Hardware", [
        Page("display", "Display", "video-display-symbolic", display.build,
             ("display", "monitor", "resolution", "scale", "refresh", "rotation",
              "night light", "color temperature")),
        Page("audio", "Audio", "audio-volume-high-symbolic", audio.build,
             ("audio", "sound", "volume", "output", "input", "microphone",
              "per-app", "pavucontrol")),
        Page("power", "Power", "battery-full-symbolic", power.build,
             ("power", "battery", "energy", "profile", "brightness", "suspend",
              "idle", "screen off", "sleep")),
        Page("printers", "Printers", "printer-symbolic", printers.build,
             ("printer", "cups", "print")),
    ]),
    Section("Privacy & Security", [
        Page("firewall", "Firewall", "security-high-symbolic", firewall.build,
             ("firewall", "ufw", "security", "incoming", "block", "ports")),
        Page("lock", "Screen Lock", "system-lock-screen-symbolic", lock.build,
             ("lock", "screen", "lockscreen", "security", "password")),
    ]),
    Section("Personalization", [
        Page("panel", "Panel & Dock", "view-dual-symbolic", panel.build,
             ("panel", "dock", "bar", "eww", "taskbar")),
        Page("locale", "Region & Time", "input-keyboard-symbolic", locale.build,
             ("region", "time", "timezone", "date", "language", "locale",
              "keyboard", "layout", "ntp")),
        Page("settings", "Appearance", "emblem-system-symbolic", settings.build,
             ("appearance", "theme", "accent", "color scheme", "dark", "light",
              "icons", "font", "cursor", "wallpaper", "window buttons", "gtk")),
        Page("accessibility", "Accessibility", "preferences-desktop-accessibility-symbolic",
             accessibility.build,
             ("accessibility", "a11y", "large text", "contrast", "animations", "zoom")),
    ]),
]

# -- Software Hub — Paketverwaltung ----------------------------------------
HUB_SECTIONS: list[Section] = [
    Section(None, [
        Page("home", "Home", "go-home-symbolic", hub_home.build,
             ("home", "recommended", "discover", "suggestions", "featured")),
        Page("store", "Browse", "system-search-symbolic", store.build,
             ("search", "install", "remove", "packages", "pacman", "aur",
              "flatpak", "software", "apps")),
    ]),
    Section("Packages", [
        Page("update", "Updates", "software-update-available-symbolic", update.build,
             ("update", "upgrade", "pacman", "flatpak", "aur", "packages")),
        Page("maintain", "Cleanup", "user-trash-symbolic", maintain.build,
             ("cleanup", "clean", "cache", "orphans", "trash", "disk space",
              "journal", "coredumps")),
        Page("bundles", "Bundles", "application-x-addon-symbolic", bundles.build,
             ("bundles", "packages", "install", "recommended", "suggestions",
              "dev", "gaming")),
    ]),
]

# Default-Sektionen = System Settings (Rückwärtskompatibilität).
SECTIONS: list[Section] = SETTINGS_SECTIONS

# Flache Liste über BEIDE Apps (für _select / Lookup / Tooling).
PAGES: list[Page] = [p for s in (SETTINGS_SECTIONS + HUB_SECTIONS) for p in s.pages]
