"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeleteAllCalloutsUC = void 0;
exports.makeDeleteAllCalloutsUC = makeDeleteAllCalloutsUC;
const core_1 = require("@vived/core");
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const CalloutRepo_1 = require("../Entities/CalloutRepo");
const DeleteAllCalloutsUndoRedo_1 = require("./DeleteAllCalloutsUndoRedo");
class DeleteAllCalloutsUC extends core_1.AppObjectUC {
    static addIfMissing(appObj) {
        const existing = appObj.getComponent(this.type);
        if (existing)
            return existing;
        else {
            return makeDeleteAllCalloutsUC(appObj);
        }
    }
}
exports.DeleteAllCalloutsUC = DeleteAllCalloutsUC;
DeleteAllCalloutsUC.type = "DeleteAllCalloutsUC";
DeleteAllCalloutsUC.get = (appObjects) => (0, core_1.getSingletonComponent)(DeleteAllCalloutsUC.type, appObjects);
function makeDeleteAllCalloutsUC(appObject) {
    return new DeleteAllCalloutsUCImp(appObject);
}
class DeleteAllCalloutsUCImp extends DeleteAllCalloutsUC {
    deleteAllCallouts() {
        const deletedCallouts = [];
        const calloutRepos = this.appObjects.getAllComponents(CalloutRepo_1.CalloutRepo.type);
        calloutRepos.forEach((repo) => {
            const callouts = repo.getAll();
            callouts.forEach((callout) => {
                deletedCallouts.push(callout.data);
                repo.removeForAppObject(callout.appObject.id);
                callout.appObject.dispose();
            });
        });
        (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
        new DeleteAllCalloutsUndoRedo_1.DeleteAllCalloutsUndoRedo(deletedCallouts, this.appObjects);
    }
    constructor(appObject) {
        super(appObject, DeleteAllCalloutsUC.type);
    }
}
//# sourceMappingURL=DeleteAllCalloutsUC.js.map