import * as React from 'react';
import { NavLink } from 'react-router-dom';
import { FilteredConnection } from '../components/FilteredConnection';
import { fetchSymbols } from '../symbols/backend';
import { SymbolIcon } from '../symbols/SymbolIcon';
function symbolIsActive(symbolLocation, currentLocation) {
    const currentHash = currentLocation.hash.replace('$references:external', '').replace('$references', '');
    return ((currentLocation.pathname + currentHash).startsWith(symbolLocation) ||
        (currentLocation.pathname.includes('/-/blob/') &&
            symbolLocation.startsWith(currentLocation.pathname + currentHash)));
}
const symbolIsActiveTrue = () => true;
const symbolIsActiveFalse = () => false;
const SymbolNode = ({ node, location }) => {
    const isActiveFunc = symbolIsActive(node.url, location) ? symbolIsActiveTrue : symbolIsActiveFalse;
    return (React.createElement("li", { className: "repo-rev-sidebar-symbols-node" },
        React.createElement(NavLink, { to: node.url, isActive: isActiveFunc, className: "repo-rev-sidebar-symbols-node__link", activeClassName: "repo-rev-sidebar-symbols-node__link--active" },
            React.createElement(SymbolIcon, { kind: node.kind, className: "icon-inline mr-1" }),
            React.createElement("span", { className: "repo-rev-sidebar-symbols-node__name" }, node.name),
            node.containerName && (React.createElement("span", { className: "repo-rev-sidebar-symbols-node__container-name" },
                React.createElement("small", null, node.containerName))),
            React.createElement("span", { className: "repo-rev-sidebar-symbols-node__path" },
                React.createElement("small", null, node.location.resource.path)))));
};
class FilteredSymbolsConnection extends FilteredConnection {
}
export class RepoRevSidebarSymbols extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.fetchSymbols = (args) => fetchSymbols(this.props.repoID, this.props.rev || '', args);
    }
    render() {
        return (React.createElement(FilteredSymbolsConnection, { className: "repo-rev-sidebar-symbols", compact: true, noun: "symbol", pluralNoun: "symbols", queryConnection: this.fetchSymbols, nodeComponent: SymbolNode, nodeComponentProps: { location: this.props.location }, defaultFirst: 100, shouldUpdateURLQuery: false, history: this.props.history, location: this.props.location }));
    }
}
//# sourceMappingURL=RepoRevSidebarSymbols.js.map