import * as _ from 'lodash';
import * as React from 'react';
import styled from '@emotion/styled';
import { CMDPalletSearchEngine, CMDPalletSearchEngineResult, CommandPalletEntryWidget, KeyboardShortcutPillsWidget } from '@journeyapps-labs/reactor-mod';
var S;
(function (S) {
    S.Left = styled.div `
    display: flex;
    justify-content: flex-end;
    flex-grow: 1;
  `;
})(S || (S = {}));
export class MonacoCommandPalletSearchEngine extends CMDPalletSearchEngine {
    constructor(options2) {
        super({
            displayName: 'Editor',
            priority: 1000
        });
        this.options2 = options2;
    }
    getShortcuts(action) {
        if (!action) {
            return null;
        }
        return (React.createElement(S.Left, null,
            React.createElement(KeyboardShortcutPillsWidget, { chord: action.chord })));
    }
    doSearch(event) {
        const result = new CMDPalletSearchEngineResult(this);
        result.setValues(_.filter(this.options2.keybindingStore.getContextualActions(), (action) => {
            return !!event.matches(action.label, {
                nullIsTrue: true
            });
        }).map((action) => {
            return {
                key: `monaco-shortcut-${action.label}`,
                action: action,
                engine: this,
                getWidget: (event) => {
                    const shortcuts = this.options2.handler.getShortcutsForAction(this.options2.handler.getMetaForAction(action.id));
                    return (React.createElement(CommandPalletEntryWidget, { key: event.key, color: "red", icon: "i-cursor", primary: action.label, selected: event.selected, mouseEntered: event.mouseEntered, mouseClicked: event.mouseClicked }, this.getShortcuts(shortcuts[0])));
                }
            };
        }));
        return result;
    }
    async handleSelection(entry, event) {
        await entry.action.run();
        return true;
    }
}
//# sourceMappingURL=MonacoCommandPalletSearchEngine.js.map