import * as tslib_1 from "tslib";
import FolderIcon from 'mdi-react/FolderIcon';
import * as React from 'react';
import { SymbolIcon } from '../../symbols/SymbolIcon';
import { RepositoryIcon } from '../../util/icons'; // TODO: Switch to mdi icon
import { basename, dirname } from '../../util/path';
export function createSuggestion(item) {
    switch (item.__typename) {
        case 'Repository': {
            return {
                type: 'repo',
                title: item.name,
                url: `/${item.name}`,
                urlLabel: 'go to repository',
            };
        }
        case 'File': {
            const descriptionParts = [];
            const dir = dirname(item.path);
            if (dir !== undefined && dir !== '.') {
                descriptionParts.push(`${dir}/`);
            }
            descriptionParts.push(basename(item.repository.name));
            if (item.isDirectory) {
                return {
                    type: 'dir',
                    title: item.name,
                    description: descriptionParts.join(' — '),
                    url: `${item.url}?suggestion`,
                    urlLabel: 'go to dir',
                };
            }
            return {
                type: 'file',
                title: item.name,
                description: descriptionParts.join(' — '),
                url: `${item.url}?suggestion`,
                urlLabel: 'go to file',
            };
        }
        case 'Symbol': {
            return {
                type: 'symbol',
                kind: item.kind,
                title: item.name,
                description: `${item.containerName || item.location.resource.path} — ${basename(item.location.resource.repository.name)}`,
                url: item.url,
                urlLabel: 'go to definition',
            };
        }
    }
}
const SuggestionIcon = (_a) => {
    var { suggestion } = _a, passThru = tslib_1.__rest(_a, ["suggestion"]);
    switch (suggestion.type) {
        case 'repo':
            return React.createElement(RepositoryIcon, Object.assign({}, passThru));
        case 'dir':
            return React.createElement(FolderIcon, null);
        case 'file':
            return React.createElement(SymbolIcon, Object.assign({ kind: "FILE" /* FILE */ }, passThru));
        case 'symbol':
            return React.createElement(SymbolIcon, Object.assign({ kind: suggestion.kind }, passThru));
    }
};
export const SuggestionItem = ({ suggestion, isSelected, onClick, liRef }) => (React.createElement("li", { className: 'suggestion' + (isSelected ? ' suggestion--selected' : ''), onMouseDown: onClick, ref: liRef },
    React.createElement(SuggestionIcon, { className: "icon-inline suggestion__icon", suggestion: suggestion }),
    React.createElement("div", { className: "suggestion__title" }, suggestion.title),
    React.createElement("div", { className: "suggestion__description" }, suggestion.description),
    React.createElement("div", { className: "suggestion__action", hidden: !isSelected },
        React.createElement("kbd", null, "enter"),
        " ",
        suggestion.urlLabel)));
//# sourceMappingURL=Suggestion.js.map