"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InitializeLabelDropLabelHook = void 0;
const core_1 = require("@vived/core");
const Entities_1 = require("../../Label/Entities");
const LabelDropItemEntity_1 = require("../Entities/LabelDropItemEntity");
class InitializeLabelDropLabelHook extends core_1.AppObjectUC {
    get item() {
        return this.getCachedLocalComponent(LabelDropItemEntity_1.LabelDropItemEntity.type);
    }
    constructor(appObject) {
        super(appObject, InitializeLabelDropLabelHook.type);
        this.onChangeLabelDropEntity = () => {
            if (!this.item)
                return;
            if (this.item.label || this.item.targetIds.length > 1) {
                this.item.removeChangeObserver(this.onChangeLabelDropEntity);
                return;
            }
            if (this.item.targetIds.length === 0) {
                return;
            }
            const firstTarget = this.item.targetIds[0];
            const label = Entities_1.LabelEntity.getByID(firstTarget, this.appObjects);
            if (!label) {
                return;
            }
            this.item.removeChangeObserver(this.onChangeLabelDropEntity);
            this.item.label = label.display;
        };
        this.item?.addChangeObserver(this.onChangeLabelDropEntity);
    }
}
exports.InitializeLabelDropLabelHook = InitializeLabelDropLabelHook;
InitializeLabelDropLabelHook.type = "InitializeLabelDropLabelHook";
//# sourceMappingURL=InitializeLabelDropLabelHook.js.map