import { AppObjectUC } from "@vived/core";
import { LabelEntity } from "../../Label/Entities";
import { LabelDropItemEntity } from "../Entities/LabelDropItemEntity";
export class InitializeLabelDropLabelHook extends AppObjectUC {
    get item() {
        return this.getCachedLocalComponent(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 = LabelEntity.getByID(firstTarget, this.appObjects);
            if (!label) {
                return;
            }
            this.item.removeChangeObserver(this.onChangeLabelDropEntity);
            this.item.label = label.display;
        };
        this.item?.addChangeObserver(this.onChangeLabelDropEntity);
    }
}
InitializeLabelDropLabelHook.type = "InitializeLabelDropLabelHook";
//# sourceMappingURL=InitializeLabelDropLabelHook.js.map