import QtQuick
import "../.."
import "../../Window" as ShellWindow

ShellWindow.Window {
    id: powerMenuWindow
    property var manager: ShellStateManager

    property var powerMenuApp: null

    width: 1217 + 52
    height: 767 + 52
    visible: manager ? manager.powerMenuOpen : false
    anchors.centerIn: parent

    Loader {
        id: powerMenuLoader
        anchors.fill: parent
        asynchronous: true
        source: "./PowerMenuApp.qml"
        onLoaded: {
            powerMenuApp = item;
            if (powerMenuApp)
                powerMenuApp.manager = manager;
        }
    }

    onManagerChanged: {
        if (powerMenuApp)
            powerMenuApp.manager = manager;
    }

    QtObject {
        id: powerMenuKeyHandler
        function handle(key) {
            if (powerMenuApp && powerMenuApp.handleKey)
                return powerMenuApp.handleKey(key);
            return false;
        }

        Component.onCompleted: ShellInputManager.registerHandler("powerMenu", handle)
        Component.onDestruction: ShellInputManager.unregisterHandler("powerMenu")
    }
}
