import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { dispatchStateChange } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { CalloutRepo } from "../Entities/CalloutRepo";
import { DeleteAllCalloutsUndoRedo } from "./DeleteAllCalloutsUndoRedo";
export class DeleteAllCalloutsUC extends AppObjectUC {
    static addIfMissing(appObj) {
        const existing = appObj.getComponent(this.type);
        if (existing)
            return existing;
        else {
            return makeDeleteAllCalloutsUC(appObj);
        }
    }
}
DeleteAllCalloutsUC.type = "DeleteAllCalloutsUC";
DeleteAllCalloutsUC.get = (appObjects) => getSingletonComponent(DeleteAllCalloutsUC.type, appObjects);
export function makeDeleteAllCalloutsUC(appObject) {
    return new DeleteAllCalloutsUCImp(appObject);
}
class DeleteAllCalloutsUCImp extends DeleteAllCalloutsUC {
    deleteAllCallouts() {
        const deletedCallouts = [];
        const calloutRepos = this.appObjects.getAllComponents(CalloutRepo.type);
        calloutRepos.forEach((repo) => {
            const callouts = repo.getAll();
            callouts.forEach((callout) => {
                deletedCallouts.push(callout.data);
                repo.removeForAppObject(callout.appObject.id);
                callout.appObject.dispose();
            });
        });
        dispatchStateChange(this.appObjects);
        new DeleteAllCalloutsUndoRedo(deletedCallouts, this.appObjects);
    }
    constructor(appObject) {
        super(appObject, DeleteAllCalloutsUC.type);
    }
}
//# sourceMappingURL=DeleteAllCalloutsUC.js.map