"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InspectorTabEntity = void 0;
exports.makeInspectorTabEntity = makeInspectorTabEntity;
const core_1 = require("@vived/core");
class InspectorTabEntity extends core_1.AppObjectEntity {
}
exports.InspectorTabEntity = InspectorTabEntity;
InspectorTabEntity.type = "InspectorTabEntity";
InspectorTabEntity.get = (appObjects) => (0, core_1.getSingletonComponent)(InspectorTabEntity.type, appObjects);
function makeInspectorTabEntity(appObject) {
    return new InspectorTabEntityImp(appObject);
}
class InspectorTabEntityImp extends InspectorTabEntity {
    get inspectorTabs() {
        return [...this._inspectorTabs];
    }
    setInspectorTabs(tabs) {
        this._inspectorTabs = [...tabs];
        if (tabs.length === 0)
            return;
        this.memoizedIndex.val = 0;
    }
    get activeTabIndex() {
        return this.memoizedIndex.val;
    }
    set activeTabIndex(val) {
        if (val < 0 || val >= this._inspectorTabs.length) {
            this.warn("Invalid index: " + val);
            return;
        }
        this.memoizedIndex.val = val;
    }
    get activeTab() {
        if (this.memoizedIndex.val < 0)
            return "";
        return this._inspectorTabs[this.memoizedIndex.val];
    }
    set activeTab(inspectorTab) {
        const index = this._inspectorTabs.indexOf(inspectorTab);
        if (index === undefined || index < 0) {
            this.warn("Unknown inspector tab: " + inspectorTab);
            return;
        }
        this.memoizedIndex.val = index;
    }
    constructor(appObject) {
        super(appObject, InspectorTabEntity.type);
        this._inspectorTabs = [];
        this.memoizedIndex = new core_1.MemoizedNumber(-1, this.notifyOnChange);
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=InspectorTabEntity.js.map