import QtQuick
import Quickshell
import Quickshell.Hyprland
import Quickshell.Io

import "../../states/wallpaperdir" as Global


Item {  // container, invisible
    id: wlLoader

    Process {
        id: getWallpaper
        command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/scripts/wallpaper_dir.sh"]
        stdout: StdioCollector {
            onStreamFinished: function() {
                console.log("getWallpaper: " + this.text)

                Global.WallpaperState.wallpaperDir = this.text.trim()

                wlogoutLoader.active = true
            }
        }
    }

    Loader {
        id: wlogoutLoader
        active: false
        sourceComponent: Wlogout {
            id: wLogout
        }
    }

    GlobalShortcut {
        name: "WLogout"
        description: "Open WLogout"

        onPressed: {
            console.log("Pressed Meta+Shift+W (Hyprland global shortcut)")
            getWallpaper.running = true
            // wlogoutLoader.active = !wlogoutLoader.active
        }
    }

    function openWlogout() {
        wlogoutLoader.active = true
    }

    function closeWlogout() {
        wlogoutLoader.active = false
    }
}