"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SerializeBaseAppState = void 0;
const core_1 = require("@vived/core");
const StateMachine_1 = require("../../StateMachine");
const Entity_1 = require("../Entity");
class SerializeBaseAppState extends core_1.AppObjectUC {
    get baseAppState() {
        return this.getCachedSingleton(Entity_1.BaseAppState.type);
    }
    getSystemState() {
        if (!this.baseAppState)
            return {};
        const state = {
            slideText: this.baseAppState.slideText,
            slideInfoContentHeight: this.baseAppState.slideInfoContentHeight,
        };
        return state;
    }
    applySystemState(state, version) {
        if (version === 1) {
            this.applyStateV1(state);
        }
        else {
            this.applyDefaultState();
        }
    }
    applyStateV1(state) {
        if (!this.baseAppState)
            return;
        if (state.slideText === undefined ||
            state.slideInfoContentHeight === undefined) {
            this.applyDefaultState();
            return;
        }
        this.baseAppState.slideText = state.slideText;
        this.baseAppState.slideInfoContentHeight = state.slideInfoContentHeight;
    }
    applyDefaultState() {
        if (!this.baseAppState)
            return;
        this.baseAppState.slideText = "";
        this.baseAppState.slideInfoContentHeight = 0;
    }
    constructor(appObject) {
        super(appObject, SerializeBaseAppState.type);
        this.name = "base-app-state";
        this.seriliziationVersion = 1;
        const stateMachine = StateMachine_1.StateMachineEntity.get(appObject.appObjectRepo);
        if (stateMachine) {
            stateMachine.registerSerializedSystem(this);
        }
        else {
            this.warn("Unable to find StateMachineEntity");
        }
    }
}
exports.SerializeBaseAppState = SerializeBaseAppState;
SerializeBaseAppState.type = "SerializeBaseAppState";
//# sourceMappingURL=SerializeBaseAppState.js.map