import ChevronDownIcon from 'mdi-react/ChevronDownIcon';
import ChevronUpIcon from 'mdi-react/ChevronUpIcon';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { DiffStat } from './DiffStat';
import { FileDiffHunks } from './FileDiffHunks';
/** A file diff. */
export class FileDiffNode extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = { expanded: true };
        this.toggleExpand = () => this.setState(prevState => ({ expanded: !prevState.expanded }));
    }
    render() {
        const node = this.props.node;
        let path;
        if (node.newPath && (node.newPath === node.oldPath || !node.oldPath)) {
            path = React.createElement("span", { title: node.newPath }, node.newPath);
        }
        else if (node.newPath && node.oldPath && node.newPath !== node.oldPath) {
            path = (React.createElement("span", { title: `${node.oldPath} ⟶ ${node.newPath}` },
                node.oldPath,
                " \u27F6 ",
                node.newPath));
        }
        else {
            // By process of elimination (that TypeScript is unfortunately unable to infer, except
            // by reorganizing this code in a way that's much more complex to humans), node.oldPath
            // is non-null.
            path = React.createElement("span", { title: node.oldPath }, node.oldPath);
        }
        const anchor = `diff-${node.internalID}`;
        return (React.createElement(React.Fragment, null,
            React.createElement("a", { id: anchor }),
            React.createElement("div", { className: `file-diff-node card ${this.props.className || ''}` },
                React.createElement("div", { className: "card-header file-diff-node__header" },
                    React.createElement("div", { className: "file-diff-node__header-path-stat" },
                        React.createElement(DiffStat, { added: node.stat.added, changed: node.stat.changed, deleted: node.stat.deleted, className: "file-diff-node__header-stat" }),
                        React.createElement(Link, { to: Object.assign({}, this.props.location, { hash: anchor }), className: "file-diff-node__header-path" }, path)),
                    React.createElement("div", { className: "file-diff-node__header-actions" },
                        React.createElement(Link, { to: node.mostRelevantFile.url, className: "btn btn-sm", "data-tooltip": "View file at revision" }, "View"),
                        React.createElement("button", { type: "button", className: "btn btn-sm btn-icon ml-2", onClick: this.toggleExpand }, this.state.expanded ? (React.createElement(ChevronDownIcon, { className: "icon-inline" })) : (React.createElement(ChevronUpIcon, { className: "icon-inline" }))))),
                this.state.expanded && (React.createElement(FileDiffHunks, { className: "file-diff-node__hunks", fileDiffAnchor: anchor, base: Object.assign({}, this.props.base, { filePath: node.oldPath }), head: Object.assign({}, this.props.head, { filePath: node.newPath }), hunks: node.hunks, lineNumbers: this.props.lineNumbers, extensions: this.props.extensions, history: this.props.history, location: this.props.location, hoverifier: this.props.hoverifier })))));
    }
}
//# sourceMappingURL=FileDiffNode.js.map