"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InspectorTabPM = exports.defaultInspectorTabVM = void 0;
exports.makeInspectorTabPM = makeInspectorTabPM;
const core_1 = require("@vived/core");
const InspectorTabEntity_1 = require("../Entities/InspectorTabEntity");
exports.defaultInspectorTabVM = {
    selectedTab: "",
    selectedTabIndex: 0,
    tabs: [],
};
class InspectorTabPM extends core_1.AppObjectPM {
}
exports.InspectorTabPM = InspectorTabPM;
InspectorTabPM.type = "InspectorTabPM";
InspectorTabPM.get = (appObjects) => (0, core_1.getSingletonComponent)(InspectorTabPM.type, appObjects);
function makeInspectorTabPM(appObject) {
    return new InspectorTabPMImp(appObject);
}
class InspectorTabPMImp extends InspectorTabPM {
    get tabEntity() {
        return this.getCachedSingleton(InspectorTabEntity_1.InspectorTabEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.selectedTab !== b.selectedTab)
            return false;
        if (a.selectedTabIndex !== b.selectedTabIndex)
            return false;
        if (a.tabs.length !== b.tabs.length)
            return false;
        let listsAreTheSame = true;
        a.tabs.forEach((tabA, i) => {
            const tabB = b.tabs[i];
            if (tabA !== tabB)
                listsAreTheSame = false;
        });
        return listsAreTheSame;
    }
    constructor(appObject) {
        super(appObject, InspectorTabPM.type);
        this.onAppStateChange = () => {
            if (!this.tabEntity)
                return;
            this.doUpdateView({
                selectedTab: this.tabEntity.activeTab,
                tabs: this.tabEntity.inspectorTabs,
                selectedTabIndex: this.tabEntity.activeTabIndex,
            });
        };
        this.tabEntity?.addChangeObserver(this.onAppStateChange);
        this.onAppStateChange();
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=InspectorTabPM.js.map