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 _EffectHandler_onEvent;
/** Manages communications to the devvit-ui-effect Event bus. */
export class EffectHandler {
    constructor(host) {
        _EffectHandler_onEvent.set(this, void 0);
        this.host = host;
        __classPrivateFieldSet(this, _EffectHandler_onEvent, this.onEvent.bind(this), "f");
        host.addController(this);
    }
    hostConnected() {
        this.host.addEventListener('devvit-ui-effect', __classPrivateFieldGet(this, _EffectHandler_onEvent, "f"));
    }
    hostDisconnected() {
        this.host.removeEventListener('devvit-ui-effect', __classPrivateFieldGet(this, _EffectHandler_onEvent, "f"));
    }
}
_EffectHandler_onEvent = new WeakMap();
/**
 * postMessage() to a specified window and host origin. Most commonly used in
 * iframe situations, so that effect details can be sent to the iframe parent,
 * instead of the iframe window itself.
 *
 * Currently only used by
 * [d2x](https://github.snooguts.net/reddit/reddit-desktop/blob/598aedf/src/reddit/components/DevvitCustomPost/index.tsx#L116)
 * but you can't delete this since it'll run @devvit/ui-renderer@next.
 *
 * @internal
 */
export function postEffectToWindow(parent, msg) {
    const { windowTop, postMessageHostOrigin } = parent;
    if (!windowTop && !postMessageHostOrigin)
        return;
    windowTop.postMessage(msg, postMessageHostOrigin);
}
//# sourceMappingURL=effect-handler.js.map