import GithubCircleIcon from 'mdi-react/GithubCircleIcon';
import SourceBranchIcon from 'mdi-react/SourceBranchIcon';
import TagIcon from 'mdi-react/TagIcon';
import React from 'react';
export const GitRefTag = ({ gitRef, onMouseDown }) => {
    // TODO(sqs): make not github specific
    const githubRepoURL = gitRef.repository.name.startsWith('github.com/')
        ? `https://${gitRef.repository.name}`
        : undefined;
    const abbrevName = gitRef.name.slice(gitRef.prefix.length);
    let kind = '';
    let url = githubRepoURL || '';
    let Icon;
    switch (gitRef.prefix) {
        case 'refs/heads/':
            kind = 'branch';
            url = url && `${url}/compare/${encodeURIComponent(abbrevName)}`;
            Icon = SourceBranchIcon;
            break;
        case 'refs/tags/':
            kind = 'tag';
            url = url && `${url}/releases/tag/${encodeURIComponent(abbrevName)}`;
            Icon = TagIcon;
            break;
        case 'refs/pull/':
            if (gitRef.name.endsWith('/head')) {
                kind = 'pull request';
                url = url && `${url}/pull/${abbrevName.split('/')[0]}`;
                Icon = GithubCircleIcon;
            }
            else if (gitRef.name.endsWith('/merge')) {
                kind = 'pull request merge';
                url = url && `${url}/pull/${abbrevName.split('/')[0]}`;
                Icon = GithubCircleIcon;
            }
            break;
    }
    // Render <a> if there's a canonical URL for the Git ref. Otherwise render <span>.
    const children = [
        Icon && React.createElement(Icon, { key: 1, className: "icon-inline" }),
        React.createElement("span", { key: 2, className: "git-ref-tag__display-name" }, gitRef.displayName),
    ];
    const props = {
        title: `${gitRef.name} ${kind ? `(${kind})` : ''}`,
        className: 'git-ref-tag',
    };
    return url ? (React.createElement("a", Object.assign({ href: url }, props, { onMouseDown: onMouseDown }), children)) : (React.createElement("span", Object.assign({}, props), children));
};
//# sourceMappingURL=GitRefTag.js.map