import QtQuick
import Quickshell
import qs.config
import qs.services

SettingsPage {
    id: root

    title: "About"
    lede: "A curated Hyprland desktop built around focus, speed, and good taste."

    Component.onCompleted: {
        if (!MachineInfo.scanned)
            MachineInfo.refresh();
        if (GraphicsDevices.devices.length === 0)
            GraphicsDevices.refresh();
    }

    SettingsCard {
        title: "Desktop"
        subtitle: "Tokyo Night Moon · Prism glass · native tiling"

        TextRow {
            label: "Hyprland"
            value: SystemSettings.hyprlandVersion || "Detecting…"
        }
        TextRow {
            label: "Quickshell"
            value: SystemSettings.quickshellVersion
        }
        TextRow {
            label: "Display"
            value: SystemSettings.monitorName || "Detecting…"
        }
        TextRow {
            label: "Configuration"
            detail: Quickshell.shellDir
            value: "Local"
            divider: false
        }
    }

    // What GNOME's About panel answers and this page did not: what am I running
    // on. Rows come from MachineInfo, except graphics, which is joined from
    // GraphicsDevices rather than read a second time -- two readouts of the same
    // hardware are two things that can disagree.
    //
    // The join splices the GPU rows in directly after Processor rather than
    // appending them, so the card reads the way fastfetch does: what the system
    // is, then what is installed on it, then the hardware underneath. A GPU
    // listed after "Disk" reads as an afterthought.
    readonly property var machineRows: {
        const rows = (MachineInfo.facts ?? []).slice();
        const gpus = GraphicsDevices.devices ?? [];
        if (gpus.length === 0)
            return rows;

        const graphics = gpus.map((device, index) => ({
            label: gpus.length > 1 ? "Graphics " + (index + 1) : "Graphics",
            value: device.name
        }));

        const after = rows.findIndex(row => row.label === "Processor");
        if (after < 0)
            return rows.concat(graphics);
        return rows.slice(0, after + 1).concat(graphics, rows.slice(after + 1));
    }

    SettingsCard {
        title: "This machine"
        subtitle: "Hardware and system, as the kernel reports it."

        Repeater {
            model: root.machineRows

            TextRow {
                id: machineRow
                required property var modelData
                required property int index

                label: machineRow.modelData.label
                value: machineRow.modelData.value
                divider: machineRow.index < root.machineRows.length - 1
            }
        }

        TextRow {
            visible: MachineInfo.scanned && root.machineRows.length === 0
            label: "Hardware"
            detail: "The system did not report anything readable"
            value: "Unavailable"
            divider: false
        }
    }

    SettingsCard {
        title: "Design principles"

        TextRow {
            label: "Curated by default"
            detail: "Strong choices instead of an incoherent matrix of switches"
        }
        TextRow {
            label: "Quiet while idle"
            detail: "No continuous decorative repaint loops"
        }
        TextRow {
            label: "Real system boundaries"
            detail: "Every control either works or clearly hands off to its owner"
            divider: false
        }
    }
}
