import { AppObjectEntityRepo, generateUniqueID, } from "@vived/core";
import { Transform3D } from "../../Transform3D/Entities/Transform3D";
import { makeCalloutEntity } from "./CalloutEntity";
export class CalloutRepo extends 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);
        }
    }
}
CalloutRepo.type = "CALLOUT_REPO";
export 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 ?? 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 makeCalloutEntity(ao);
        };
        this._transform = Transform3D.addIfMissing(appObject);
    }
}
//# sourceMappingURL=CalloutRepo.js.map