import * as React from 'react';
import { LinkOrSpan } from '../components/LinkOrSpan';
import { toPrettyBlobURL, toTreeURL } from '../util/url';
/**
 * A breadcrumb where each path component is a separate link. Use this sparingly. Usually having the entire path be
 * a single link target is more usable; in that case, use RepoFileLink.
 */
class Breadcrumb extends React.Component {
    render() {
        const parts = this.props.path.split('/');
        const spans = [];
        for (const [i, part] of parts.entries()) {
            const link = this.props.partToUrl(i);
            const className = `part ${this.props.partToClassName ? this.props.partToClassName(i) : ''} ${i === parts.length - 1 ? 'part-last' : ''}`;
            spans.push(React.createElement(LinkOrSpan, { key: i, className: className, to: link }, part));
            if (i < parts.length - 1) {
                spans.push(React.createElement("span", { key: 'sep' + i, className: "breadcrumb__separator" }, "/"));
            }
        }
        return (
        // Important: do not put spaces between the breadcrumbs or spaces will get added when copying the path
        React.createElement("span", { className: "breadcrumb" }, spans));
    }
}
/**
 * Displays a file path in a repository in breadcrumb style, with ancestor path
 * links.
 */
export const FilePathBreadcrumb = ({ repoPath, rev, filePath, isDir }) => {
    const parts = filePath.split('/');
    // tslint:disable-next-line:jsx-no-lambda
    return (React.createElement(Breadcrumb, { path: filePath, 
        // tslint:disable-next-line:jsx-no-lambda
        partToUrl: i => {
            const partPath = parts.slice(0, i + 1).join('/');
            if (isDir || i < parts.length - 1) {
                return toTreeURL({ repoPath, rev, filePath: partPath });
            }
            return toPrettyBlobURL({ repoPath, rev, filePath: partPath });
        }, 
        // tslint:disable-next-line:jsx-no-lambda
        partToClassName: i => (i === parts.length - 1 ? 'part-last' : 'part-directory') }));
};
//# sourceMappingURL=FilePathBreadcrumb.js.map