"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MakeTransparentUC = void 0;
exports.makeMakeTransparentUC = makeMakeTransparentUC;
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const UndoRedo_1 = require("../../UndoRedo");
const Entities_1 = require("../Entities");
class MakeTransparentUC extends core_1.AppObjectUC {
    static get(id, appObjects) {
        const appObj = appObjects.get(id);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(MakeTransparentUC.type);
    }
}
exports.MakeTransparentUC = MakeTransparentUC;
MakeTransparentUC.type = "MakeTransparentUC";
function makeMakeTransparentUC(appObject) {
    return new MakeTransparentUCImp(appObject);
}
class MakeTransparentUCImp extends MakeTransparentUC {
    get transparency() {
        return this.getCachedLocalComponent(Entities_1.Transparency.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(Dispatcher_1.DispatchStateChangeUC.type)?.doDispatch;
    }
    get undoRedo() {
        return this.getCachedSingleton(UndoRedo_1.UndoRedoEntity.type);
    }
    constructor(appObject) {
        super(appObject, MakeTransparentUC.type);
        this.makeTransparent = () => {
            if (!this.transparency || this.transparency.isTransparent) {
                return;
            }
            this.transparency.isTransparent = true;
            if (this.dispatchStateChange)
                this.dispatchStateChange();
            this.submitUndo();
        };
        this.toggleIsTransparent = () => {
            if (!this.transparency) {
                return;
            }
            this.transparency.isTransparent = !this.transparency.isTransparent;
            if (this.dispatchStateChange)
                this.dispatchStateChange();
            this.submitUndo();
        };
        this.submitUndo = () => {
            const transparency = this.transparency;
            const dispatcher = this.dispatchStateChange;
            if (!transparency || !dispatcher || !this.undoRedo) {
                return;
            }
            const undoState = !transparency.isTransparent;
            const action = {
                undoAction: () => {
                    transparency.isTransparent = undoState;
                    dispatcher();
                },
                redoAction: () => {
                    transparency.isTransparent = !undoState;
                    dispatcher();
                },
            };
            this.undoRedo.submitAction(action);
        };
    }
}
//# sourceMappingURL=MakeTransparentUC.js.map