"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalloutRepo = void 0;
exports.makeCalloutRepoEntity = makeCalloutRepoEntity;
const core_1 = require("@vived/core");
const Transform3D_1 = require("../../Transform3D/Entities/Transform3D");
const CalloutEntity_1 = require("./CalloutEntity");
class CalloutRepo extends core_1.AppObjectEntityRepo {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(this.type);
    }
    static addIfMissing(appObject) {
        const existing = appObject.getComponent(CalloutRepo.type);
        if (existing) {
            return existing;
        }
        else {
            return makeCalloutRepoEntity(appObject);
        }
    }
}
exports.CalloutRepo = CalloutRepo;
CalloutRepo.type = "CALLOUT_REPO";
function makeCalloutRepoEntity(appObject) {
    return new CalloutRepoImp(appObject);
}
class CalloutRepoImp extends CalloutRepo {
    get transform() {
        return this._transform;
    }
    deleteCallout(id) {
        const callout = this.getForAppObject(id);
        if (!callout)
            return;
        callout.appObject.dispose();
        this.removeForAppObject(id);
    }
    constructor(appObject) {
        super(appObject, CalloutRepo.type);
        this.applySurrogateTransform = (transform) => {
            this._transform = transform;
        };
        this.makeCallout = (id) => {
            const idToUse = id ?? (0, core_1.generateUniqueID)();
            const callout = this.calloutFactory(idToUse);
            callout.inRepo = this;
            callout.rootTransform.parent = this._transform;
            callout.labelTransform.parent = this._transform;
            this.add(callout);
            return callout;
        };
        this.calloutFactory = (id) => {
            const ao = this.appObjects.getOrCreate(id);
            return (0, CalloutEntity_1.makeCalloutEntity)(ao);
        };
        this._transform = Transform3D_1.Transform3D.addIfMissing(appObject);
    }
}
//# sourceMappingURL=CalloutRepo.js.map