import { AppObjectUC } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher";
import { UndoRedoEntity } from "../../UndoRedo";
import { Transparency } from "../Entities";
export class MakeTransparentUC extends AppObjectUC {
    static get(id, appObjects) {
        const appObj = appObjects.get(id);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(MakeTransparentUC.type);
    }
}
MakeTransparentUC.type = "MakeTransparentUC";
export function makeMakeTransparentUC(appObject) {
    return new MakeTransparentUCImp(appObject);
}
class MakeTransparentUCImp extends MakeTransparentUC {
    get transparency() {
        return this.getCachedLocalComponent(Transparency.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(DispatchStateChangeUC.type)?.doDispatch;
    }
    get undoRedo() {
        return this.getCachedSingleton(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