"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyboardToSetTab = void 0;
const core_1 = require("@vived/core");
const BaseAppState_1 = require("../../BaseApp/Entity/BaseAppState");
const KeyboardInput_1 = require("../../KeyboardInput/Entities/KeyboardInput");
const Entities_1 = require("../Entities");
class KeyboardToSetTab extends core_1.AppObjectController {
    get inspectorTabEntity() {
        return this.getCachedSingleton(Entities_1.InspectorTabEntity.type);
    }
    get baseApp() {
        return this.getCachedSingleton(BaseAppState_1.BaseAppState.type);
    }
    constructor(appObject) {
        super(appObject, KeyboardToSetTab.type);
        this.codeLookup = new Map([
            ["Digit1", 0],
            ["Digit2", 1],
            ["Digit3", 2],
            ["Digit4", 3],
            ["Digit5", 4],
        ]);
        this.onKeyDown = (e) => {
            if (!this.inspectorTabEntity)
                return;
            if (this.baseApp?.isAuthoring !== true)
                return;
            if (!this.codeLookup.has(e.code))
                return;
            const desiredIndex = this.codeLookup.get(e.code);
            if (desiredIndex === undefined ||
                desiredIndex < 0 ||
                desiredIndex >= this.inspectorTabEntity.inspectorTabs.length) {
                return;
            }
            this.inspectorTabEntity.activeTabIndex = desiredIndex;
        };
        const keyboardInput = KeyboardInput_1.KeyboardInputEntity.get(this.appObjects);
        keyboardInput?.registerController(this);
    }
}
exports.KeyboardToSetTab = KeyboardToSetTab;
KeyboardToSetTab.type = "KeyboardToSetTab";
//# sourceMappingURL=KeyboardToSetTab.js.map