import React from "react";
import DiffFile from "./DiffFile";
import { DiffObjectProps, File } from "./DiffTypes";
import Notification from "../Notification";
import { WithTranslation, withTranslation } from "react-i18next";

type Props = WithTranslation &
  DiffObjectProps & {
    diff: File[];
    defaultCollapse?: boolean;
  };

class Diff extends React.Component<Props> {
  static defaultProps: Partial<Props> = {
    sideBySide: false
  };

  render() {
    const { diff, t, ...fileProps } = this.props;
    return (
      <>
        {diff.length === 0 ? (
          <Notification type="info">{t("noDiffFound")}</Notification>
        ) : (
          diff.map((file, index) => <DiffFile key={index} file={file} {...fileProps} {...this.props} />)
        )}
      </>
    );
  }
}

export default withTranslation("plugins")(Diff);
