import * as React from 'react';
import { FilteredConnection } from '../../components/FilteredConnection';
import { getModeFromPath } from '../../util';
import { isErrorLike } from '../../util/errors';
class FilteredFileDiffConnection extends FilteredConnection {
}
/**
 * Displays a list of file diffs.
 */
export class FileDiffConnection extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.onUpdate = (fileDiffsOrError) => {
            const nodeProps = this.props.nodeComponentProps;
            // TODO(sqs): This reports to extensions that these files are empty. This is wrong, but we don't have any
            // easy way to get the files' full contents here (and doing so would be very slow). Improve the extension
            // API's support for diffs.
            const dummyText = '';
            const visibleTextDocuments = [];
            if (fileDiffsOrError && !isErrorLike(fileDiffsOrError)) {
                for (const fileDiff of fileDiffsOrError.nodes) {
                    if (fileDiff.oldPath) {
                        visibleTextDocuments.push({
                            uri: `git://${nodeProps.base.repoPath}?${nodeProps.base.commitID}#${fileDiff.oldPath}`,
                            languageId: getModeFromPath(fileDiff.oldPath),
                            text: dummyText,
                        });
                    }
                    if (fileDiff.newPath) {
                        visibleTextDocuments.push({
                            uri: `git://${nodeProps.head.repoPath}?${nodeProps.head.commitID}#${fileDiff.newPath}`,
                            languageId: getModeFromPath(fileDiff.newPath),
                            text: dummyText,
                        });
                    }
                }
            }
            this.props.extensionsOnVisibleTextDocumentsChange(visibleTextDocuments);
        };
    }
    render() {
        return React.createElement(FilteredFileDiffConnection, Object.assign({}, this.props, { onUpdate: this.onUpdate }));
    }
}
//# sourceMappingURL=FileDiffConnection.js.map