export const REMOTE_FIRE_AND_FORGET_UI_METHODS = new Set([
    'notify',
    'setStatus',
    'setWidget',
    'setTitle',
    'set_editor_text',
]);
export async function handleRemoteUiRequest(ctx, request) {
    if (!ctx.hasUI) {
        return REMOTE_FIRE_AND_FORGET_UI_METHODS.has(request.method) ? undefined : null;
    }
    const ui = ctx.ui;
    switch (request.method) {
        case 'select': {
            const options = Array.isArray(request.params.options)
                ? request.params.options.filter((option) => typeof option === 'string')
                : [];
            const title = request.params.title ?? 'Select';
            return (await ui.select(title, options)) ?? null;
        }
        case 'confirm':
            return await ui.confirm(request.params.title ?? 'Confirm?', request.params.message ?? 'Confirm?');
        case 'input':
            return ((await ui.input(request.params.title ?? 'Input', request.params.placeholder ?? '')) ?? null);
        case 'editor':
            return ((await ui.editor(request.params.title ?? 'Editor', request.params.prefill ?? '')) ?? null);
        case 'notify':
            ui.notify(request.params.message ?? '', request.params.notifyType ?? 'info');
            return undefined;
        case 'setStatus':
            ui.setStatus(request.params.statusKey ?? 'remote', request.params.statusText ?? undefined);
            return undefined;
        case 'setWidget': {
            const widgetLines = Array.isArray(request.params.widgetLines)
                ? request.params.widgetLines.filter((line) => typeof line === 'string')
                : undefined;
            const widgetPlacement = request.params.widgetPlacement;
            ui.setWidget(request.params.widgetKey ?? 'remote_widget', widgetLines, widgetPlacement === 'aboveEditor' || widgetPlacement === 'belowEditor'
                ? { placement: widgetPlacement }
                : undefined);
            return undefined;
        }
        case 'setTitle':
            ui.setTitle(request.params.title ?? '');
            return undefined;
        case 'set_editor_text':
            ui.setEditorText(request.params.text ?? '');
            return undefined;
        default:
            return null;
    }
}
//# sourceMappingURL=remote-ui-handler.js.map