import QtQuick
import qs.config
import qs.services

SettingsPage {
    title: "Startup & Services"
    lede: "A clear view of the background tools that make the desktop feel complete."

    function status(active: bool): string {
        return active ? "Running" : "Stopped";
    }

    Item {
        width: parent.width
        implicitHeight: refresh.implicitHeight

        SettingsButton {
            id: refresh
            anchors.right: parent.right
            text: SystemSettings.busy ? "Refreshing…" : "Refresh"
            enabled: !SystemSettings.busy
            onClicked: SystemSettings.refresh()
        }
    }

    SettingsCard {
        title: "Your services"

        SettingRow {
            label: "Nextcloud"
            detail: "File synchronization and tray status"
            controlWidth: 190

            Row {
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter
                spacing: 10
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    text: status(SystemSettings.nextcloudActive)
                    color: Theme.fgDim
                    font.family: Theme.fontFamily
                    font.pixelSize: Theme.fontSize
                }
                SettingsButton {
                    text: "Open"
                    onClicked: SystemSettings.openApplication("nextcloud")
                }
            }
        }

        SettingRow {
            label: "RustDesk"
            detail: "Remote access through the enabled system service"
            controlWidth: 190

            Row {
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter
                spacing: 10
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    text: status(SystemSettings.rustdeskActive)
                    color: Theme.fgDim
                    font.family: Theme.fontFamily
                    font.pixelSize: Theme.fontSize
                }
                SettingsButton {
                    text: "Open"
                    onClicked: SystemSettings.openApplication("rustdesk")
                }
            }
        }

        SettingRow {
            label: "KDE Connect"
            detail: "Phone pairing, clipboard, files, and remote controls"
            divider: false
            controlWidth: 190

            Row {
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter
                spacing: 10
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    text: status(SystemSettings.kdeconnectActive)
                    color: Theme.fgDim
                    font.family: Theme.fontFamily
                    font.pixelSize: Theme.fontSize
                }
                SettingsButton {
                    text: "Open"
                    onClicked: SystemSettings.openApplication("kdeconnect")
                }
            }
        }
    }

    SettingsCard {
        title: "Desktop foundation"

        TextRow {
            label: "Hyprpaper"
            detail: "Wallpaper service"
            value: status(SystemSettings.hyprpaperActive)
        }
        TextRow {
            label: "Hypridle"
            detail: "Idle and lock policy"
            value: status(SystemSettings.hypridleActive)
        }
        TextRow {
            label: "Vicinae"
            detail: "Spotlight-style launcher daemon"
            value: status(SystemSettings.vicinaeActive)
            divider: false
        }
    }

    SettingsCard {
        title: "Fedora system settings"
        subtitle: "These remain owned by trusted system services and GNOME's mature panels."

        ActionRow {
            label: "Network, Bluetooth, printers, users, and accounts"
            detail: "GNOME Settings remains searchable from the launcher too"
            divider: false
            action: "Open network"
            onTriggered: SystemSettings.openGnomePanel("network")
        }
    }
}
