"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SerializeAllowHoverLabel = void 0;
const core_1 = require("@vived/core");
const StateMachine_1 = require("../../StateMachine");
const HoverLabelEntity_1 = require("../Entities/HoverLabelEntity");
class SerializeAllowHoverLabel extends core_1.AppObjectUC {
    getSystemState() {
        if (!this.hoverLabelEntity) {
            return {
                allow: false,
            };
        }
        const state = {
            allow: this.hoverLabelEntity.allowHoverLabel,
        };
        return state;
    }
    applySystemState(state, version) {
        if (state && version === 1) {
            const castState = state;
            this.handleStateVersion1(castState);
        }
        else {
            // Unsupported version
            console.warn(`Unsupported data version ${version} for serialized system ${this.name}. Reverting to default state`);
            this.applyDefaultState();
        }
    }
    applyDefaultState() {
        if (!this.hoverLabelEntity)
            return;
        this.hoverLabelEntity.allowHoverLabel = true;
    }
    handleStateVersion1(data) {
        if (!this.hoverLabelEntity)
            return;
        this.hoverLabelEntity.allowHoverLabel = data.allow;
    }
    constructor(appObj) {
        super(appObj, SerializeAllowHoverLabel.type);
        this.name = "allowHoverLabel";
        this.seriliziationVersion = 1;
        this.hoverLabelEntity = this.appObject.getComponent(HoverLabelEntity_1.HoverLabelEntity.type);
        if (!this.hoverLabelEntity) {
            this.warn("Serializer has been added to an App Object that does not have a HoverLabelEntity. Add the Entity first");
            return;
        }
        const stateMachine = this.appObjects.getSingleton(StateMachine_1.StateMachineEntity.type);
        if (stateMachine) {
            stateMachine.registerSerializedSystem(this);
        }
        else {
            this.warn("Unable to find StateMachineEntity");
        }
    }
}
exports.SerializeAllowHoverLabel = SerializeAllowHoverLabel;
SerializeAllowHoverLabel.type = "SerializeAllowHoverLabel";
//# sourceMappingURL=SerializeAllowHoverLabel.js.map