import { Angle, AppObjectUC, Quaternion, Vector3, } from "@vived/core";
import { LabelEntity } from "../../Label/Entities/LabelEntity";
import { CalloutGlobals } from "../Entities/CalloutGlobals";
import { CalloutRepo } from "../Entities/CalloutRepo";
import { CreateCalloutUndoRedo } from "./CreateCalloutUndoRedo";
export class CreateCalloutUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.newLabelBumpAmount = 0.01;
    }
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(this.type);
    }
}
CreateCalloutUC.type = "CreateCalloutUC";
export function makeCreateCalloutUC(appObject) {
    return new CreateCalloutUCImp(appObject);
}
class CreateCalloutUCImp extends CreateCalloutUC {
    get repo() {
        return this.getCachedLocalComponent(CalloutRepo.type);
    }
    get calloutGlobals() {
        return this.getCachedSingleton(CalloutGlobals.type);
    }
    get repoLabel() {
        return this.getCachedLocalComponent(LabelEntity.type);
    }
    fromPick(pickHit, pickHitNormal, undoRedo = true) {
        if (!this.repo) {
            throw new Error("No Callout Repo");
        }
        const callout = this.repo.makeCallout();
        callout.rootTransform.worldPosition = pickHit;
        callout.rootTransform.worldRotation =
            Quaternion.FromDirectionVector(pickHitNormal);
        const labelBump = Vector3.NewVectorOfLength(pickHitNormal, this.newLabelBumpAmount);
        callout.labelTransform.worldPosition = Vector3.Add(labelBump, pickHit);
        callout.labelTransform.worldRotation = Quaternion.FromYawPitchRoll(Angle.FromDegrees(180), Angle.FromDegrees(0), Angle.FromDegrees(0));
        callout.label.default = this.getInitialLabel();
        if (this.calloutGlobals) {
            callout.size = this.calloutGlobals.lastSize;
            callout.overlayColor.overlayColor = this.calloutGlobals.lastColor;
        }
        if (undoRedo) {
            new CreateCalloutUndoRedo(callout.data, this.appObjects);
        }
        return callout;
    }
    getInitialLabel() {
        if (this.appObject.hasComponent(LabelEntity.type)) {
            return this.repoLabel ? this.repoLabel.display : "Callout";
        }
        else {
            return "Callout";
        }
    }
    constructor(appObject) {
        super(appObject, CreateCalloutUC.type);
    }
}
//# sourceMappingURL=CreateCalloutUC.js.map