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

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

    property var appLauncherApp: null

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

    Loader {
        id: appLauncherLoader
        anchors.fill: parent
        asynchronous: true
        source: "./AppLauncherApp.qml"
        onLoaded: {
            appLauncherApp = item;
            if (appLauncherApp)
                appLauncherApp.manager = manager;
        }
    }

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

    QtObject {
        id: appLauncherKeyHandler
        function handle(event) {
            if (appLauncherApp && appLauncherApp.handleKey)
                return appLauncherApp.handleKey(event.key);
            return false;
        }

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