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 _RemoteApp_instances, _RemoteApp_customPost, _RemoteApp_uiEventHandler, _RemoteApp_meta, _RemoteApp_uploaded, _RemoteApp_newNiceMeta;
import {} from '@devvit/protos/lib/Types.js';
import { CustomPostDefinition } from '@devvit/protos/types/devvit/reddit/custom_post/v1alpha/custom_post.js';
import {} from '@devvit/protos/types/devvit/ui/block_kit/v1beta/ui.js';
import { UIEventHandlerDefinition } from '@devvit/protos/types/devvit/ui/events/v1alpha/handle_ui.js';
import {} from '@devvit/protos/types/google/protobuf/empty.js';
import { Metadata as NiceMeta, createChannel, createClient } from 'nice-grpc-web';
export class RemoteApp {
    /** @arg uploaded Callback to test whether remote bundle is available. */
    static new(gatewayOrigin, uploaded, meta) {
        const channel = createChannel(gatewayOrigin);
        const customPost = createClient(CustomPostDefinition, channel);
        const uiEventHandler = createClient(UIEventHandlerDefinition, channel);
        return new RemoteApp(customPost, uiEventHandler, uploaded, meta);
    }
    constructor(customPost, uiEventHandler, uploaded, meta) {
        _RemoteApp_instances.add(this);
        _RemoteApp_customPost.set(this, void 0);
        _RemoteApp_uiEventHandler.set(this, void 0);
        _RemoteApp_meta.set(this, void 0);
        _RemoteApp_uploaded.set(this, void 0);
        __classPrivateFieldSet(this, _RemoteApp_customPost, customPost, "f");
        __classPrivateFieldSet(this, _RemoteApp_uiEventHandler, uiEventHandler, "f");
        __classPrivateFieldSet(this, _RemoteApp_uploaded, uploaded, "f");
        __classPrivateFieldSet(this, _RemoteApp_meta, meta, "f");
    }
    async HandleUIEvent(req, meta) {
        await __classPrivateFieldGet(this, _RemoteApp_uploaded, "f").call(this);
        return __classPrivateFieldGet(this, _RemoteApp_uiEventHandler, "f").handleUIEvent(req, {
            metadata: __classPrivateFieldGet(this, _RemoteApp_instances, "m", _RemoteApp_newNiceMeta).call(this, meta)
        });
    }
    async RenderPost(req, meta) {
        await __classPrivateFieldGet(this, _RemoteApp_uploaded, "f").call(this);
        return __classPrivateFieldGet(this, _RemoteApp_customPost, "f").renderPost(req, {
            metadata: __classPrivateFieldGet(this, _RemoteApp_instances, "m", _RemoteApp_newNiceMeta).call(this, meta)
        });
    }
    async RenderPostContent(req, meta) {
        await __classPrivateFieldGet(this, _RemoteApp_uploaded, "f").call(this);
        return __classPrivateFieldGet(this, _RemoteApp_customPost, "f").renderPostContent(req, {
            metadata: __classPrivateFieldGet(this, _RemoteApp_instances, "m", _RemoteApp_newNiceMeta).call(this, meta)
        });
    }
    async RenderPostComposer(req, meta) {
        await __classPrivateFieldGet(this, _RemoteApp_uploaded, "f").call(this);
        return __classPrivateFieldGet(this, _RemoteApp_customPost, "f").renderPostComposer(req, {
            metadata: __classPrivateFieldGet(this, _RemoteApp_instances, "m", _RemoteApp_newNiceMeta).call(this, meta)
        });
    }
}
_RemoteApp_customPost = new WeakMap(), _RemoteApp_uiEventHandler = new WeakMap(), _RemoteApp_meta = new WeakMap(), _RemoteApp_uploaded = new WeakMap(), _RemoteApp_instances = new WeakSet(), _RemoteApp_newNiceMeta = function _RemoteApp_newNiceMeta(meta) {
    return new NiceMeta(Object.entries({ ...__classPrivateFieldGet(this, _RemoteApp_meta, "f"), ...meta }).map(([key, { values }]) => [
        key,
        values.join()
    ]));
};
//# sourceMappingURL=remote-app.js.map