"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LandmarkEntity = exports.LANDMARK_MAXIMUM_SIZE = exports.LANDMARK_MINIMUM_SIZE = void 0;
exports.makeLandmarkEntity = makeLandmarkEntity;
const core_1 = require("@vived/core");
const Hideable_1 = require("../../Hideable");
const Label_1 = require("../../Label");
const OverlayColor_1 = require("../../OverlayColor");
const Selection_1 = require("../../Selection");
const Transform3D_1 = require("../../Transform3D");
exports.LANDMARK_MINIMUM_SIZE = 0.1;
exports.LANDMARK_MAXIMUM_SIZE = 2;
class LandmarkEntity extends core_1.AppObjectEntity {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
}
exports.LandmarkEntity = LandmarkEntity;
LandmarkEntity.type = "LANDMARK";
function makeLandmarkEntity(appObject) {
    const landmark = new LandmarkImp(appObject);
    return landmark;
}
class LandmarkImp extends LandmarkEntity {
    get id() {
        return this.appObject.id;
    }
    get label() {
        return this._label;
    }
    get transform() {
        return this._transform;
    }
    get hideable() {
        return this._hideable;
    }
    get overlayColor() {
        return this._overlayColor;
    }
    get selectable() {
        return this._selectable;
    }
    get size() {
        return this.memoizedSize.val;
    }
    set size(val) {
        this.memoizedSize.val = val;
    }
    get position() {
        return this._transform.localPosition;
    }
    set position(p) {
        this._transform.localPosition = p;
    }
    get rotation() {
        return this._transform.localRotation;
    }
    set rotation(r) {
        this._transform.localRotation = r;
    }
    set inRepo(val) {
        this._inRepo = val;
        this.transform.parent = val?.transform;
    }
    get inRepo() {
        return this._inRepo;
    }
    get parentID() {
        return this._inRepo ? this._inRepo.appObject.id : "";
    }
    get data() {
        return {
            id: this.appObject.id,
            parentID: this.parentID,
            position: this.position.dto,
            rotation: this.rotation.dto,
            size: this.memoizedSize.val,
            label: this._label.custom,
            defaultLabel: this._label.default,
            color: this._overlayColor.overlayColor,
        };
    }
    set data(dto) {
        this.rotation = core_1.Quaternion.FromDTO(dto.rotation);
        this.position = core_1.Vector3.FromDTO(dto.position);
        this.memoizedSize.val = dto.size;
        this._label.custom = dto.label;
        this._label.default = dto.defaultLabel;
        this._overlayColor.overlayColor = dto.color;
    }
    dispose() {
        super.dispose();
        this._label.removeChangeObserver(this.notifyOnChange);
        this._transform.removeChangeObserver(this.notifyOnChange);
        this._hideable.removeChangeObserver(this.notifyOnChange);
        this._overlayColor.removeChangeObserver(this.notifyOnChange);
        this._selectable.removeChangeObserver(this.notifyOnChange);
        this._label.dispose();
        this._transform.dispose();
        this._hideable.dispose();
        this._overlayColor.dispose();
        this._selectable.dispose();
        if (this._inRepo) {
            this._inRepo.removeForAppObject(this.appObject.id);
        }
    }
    constructor(appObject) {
        super(appObject, LandmarkEntity.type);
        this.memoizedSize = new core_1.MemoizedNumber(0, this.notifyOnChange);
        this._label = Label_1.LabelEntity.addIfMissing(appObject);
        this._label.addChangeObserver(this.notifyOnChange);
        this._transform = Transform3D_1.Transform3D.addIfMissing(appObject);
        this._transform.addChangeObserver(this.notifyOnChange);
        this._hideable = Hideable_1.Hideable.addIfMissing(appObject);
        this._hideable.addChangeObserver(this.notifyOnChange);
        this._overlayColor = OverlayColor_1.OverlayColor.addIfMissing(appObject);
        this._overlayColor.addChangeObserver(this.notifyOnChange);
        this._selectable = (0, Selection_1.makeSelectable)(appObject);
        this._selectable.addChangeObserver(this.notifyOnChange);
    }
}
//# sourceMappingURL=LandmarkEntity.js.map