"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultFramedContainerVM = exports.FramedContainerPM = void 0;
exports.makeFramedContainerPM = makeFramedContainerPM;
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
class FramedContainerPM extends core_1.AppObjectPM {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(FramedContainerPM.type);
    }
}
exports.FramedContainerPM = FramedContainerPM;
FramedContainerPM.type = "FramedContainerPM";
function makeFramedContainerPM(appObject) {
    return new FramedContainerPMImp(appObject);
}
class FramedContainerPMImp extends FramedContainerPM {
    vmsAreEqual(a, b) {
        if (a.height !== b.height)
            return false;
        if (a.width !== b.width)
            return false;
        if (a.top !== b.top)
            return false;
        if (a.left !== b.left)
            return false;
        if (a.show !== b.show)
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, FramedContainerPM.type);
        this.onContainerChange = () => {
            if (!this.container)
                return;
            const vm = {
                height: this.container.size.y,
                width: this.container.size.x,
                top: this.container.position.y,
                left: this.container.position.x,
                show: this.container.show,
            };
            this.doUpdateView(vm);
        };
        this.dispose = () => {
            this.container?.removeChangeObserver(this.onContainerChange);
        };
        this.container = appObject.getComponent(Entities_1.FramedScreenContainer.type);
        if (!this.container) {
            this.warn("FramedContainerPM has been added to an App Object that does not have a FramedScreenContainer");
            return;
        }
        this.container.addChangeObserver(this.onContainerChange);
        this.onContainerChange();
    }
}
exports.defaultFramedContainerVM = {
    height: 0,
    left: 0,
    top: 0,
    width: 0,
    show: false,
};
//# sourceMappingURL=FramedContainerPM.js.map