import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { InspectorTabEntity } from "../Entities/InspectorTabEntity";
export const defaultInspectorTabVM = {
    selectedTab: "",
    selectedTabIndex: 0,
    tabs: [],
};
export class InspectorTabPM extends AppObjectPM {
}
InspectorTabPM.type = "InspectorTabPM";
InspectorTabPM.get = (appObjects) => getSingletonComponent(InspectorTabPM.type, appObjects);
export function makeInspectorTabPM(appObject) {
    return new InspectorTabPMImp(appObject);
}
class InspectorTabPMImp extends InspectorTabPM {
    get tabEntity() {
        return this.getCachedSingleton(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