var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m") throw new TypeError("Private method is not writable");
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _ToastEffectHandler_parentWindowInfo;
import { ToastAppearance } from '@devvit/protos';
import { customEvent } from '@reddit/faceplate/lib/custom-event.js';
import { Severity } from '@reddit/faceplate/types.js';
import { EffectHandler, postEffectToWindow } from './effect-handler.js';
export class ToastEffectHandler extends EffectHandler {
    constructor(host, parentWindowInfo) {
        super(host);
        _ToastEffectHandler_parentWindowInfo.set(this, void 0);
        __classPrivateFieldSet(this, _ToastEffectHandler_parentWindowInfo, parentWindowInfo, "f");
    }
    onEvent(ev) {
        const { showToast } = ev.detail.effect;
        if (!showToast)
            return;
        if (!showToast.toast) {
            console.warn(`[toast] missing config`);
            return;
        }
        const toastDetails = {
            message: showToast.toast.text,
            level: showToast.toast.appearance === ToastAppearance.SUCCESS ? Severity.success : Severity.info,
        };
        if (__classPrivateFieldGet(this, _ToastEffectHandler_parentWindowInfo, "f")) {
            postEffectToWindow(__classPrivateFieldGet(this, _ToastEffectHandler_parentWindowInfo, "f"), {
                ...toastDetails,
                effectName: 'devvit:toastEffect',
            });
            return;
        }
        this.host.dispatchEvent(customEvent('faceplate-alert', toastDetails));
    }
}
_ToastEffectHandler_parentWindowInfo = new WeakMap();
//# sourceMappingURL=toast-effect-handler.js.map