import "choerodon-ui/lib/pagination/style";
import _Pagination from "choerodon-ui/lib/pagination";
import "choerodon-ui/lib/spin/style";
import _Spin from "@hzero-front-ui/c7n-ui/lib/Spin";
import "choerodon-ui/lib/tooltip/style";
import _Tooltip from "choerodon-ui/lib/tooltip";
import React, { Fragment } from 'react';
import { FormattedMessage } from 'react-intl';
import TimePopover from "../../../components/timePopover";
import UserInfo from "../../../components/userInfo";
import "./Submission.less";
export default function CommitHistory(props) {
  var _props$dataSource = props.dataSource,
      content = _props$dataSource.list,
      total = _props$dataSource.total,
      pageNum = _props$dataSource.pageNum,
      onPageChange = props.onPageChange,
      loading = props.loading;
  var list = [];

  if (content && content.length) {
    list = content.map(function (item) {
      var userName = item.userName,
          url = item.url,
          id = item.id,
          commitContent = item.commitContent,
          commitDate = item.commitDate,
          imgUrl = item.imgUrl,
          appServiceName = item.appServiceName,
          commitSHA = item.commitSHA;
      return /*#__PURE__*/React.createElement("div", {
        className: "c7n-report-history-item",
        key: "".concat(commitSHA, "-").concat(commitDate)
      }, /*#__PURE__*/React.createElement(UserInfo, {
        name: userName || '?',
        avatar: imgUrl,
        showName: false,
        size: "large",
        showTooltip: false
      }), /*#__PURE__*/React.createElement("div", {
        className: "c7n-report-history-info"
      }, /*#__PURE__*/React.createElement("div", {
        className: "c7n-report-history-content"
      }, /*#__PURE__*/React.createElement("a", {
        className: "c7n-report-history-link",
        href: url,
        rel: "nofollow me noopener noreferrer",
        target: "_blank"
      }, commitContent)), /*#__PURE__*/React.createElement("div", {
        className: "c7n-report-history-date"
      }, /*#__PURE__*/React.createElement("span", {
        className: "c7n-report-history-name"
      }, userName || /*#__PURE__*/React.createElement(_Tooltip, {
        placement: "top",
        title: /*#__PURE__*/React.createElement(FormattedMessage, {
          id: "report.unknown.user"
        })
      }, "Unknown")), /*#__PURE__*/React.createElement("span", null, "\uFF08", appServiceName, "\uFF09"), /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "report.commit.by"
      }), " ", /*#__PURE__*/React.createElement(TimePopover, {
        style: {
          display: 'inline-block'
        },
        content: commitDate
      }))));
    });
  } else {
    list = [/*#__PURE__*/React.createElement("span", {
      key: "no.commits",
      className: "c7n-report-history-list-none"
    }, /*#__PURE__*/React.createElement(FormattedMessage, {
      id: "report.commit.none"
    }))];
  }

  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("h3", {
    className: "c7n-report-history-title"
  }, /*#__PURE__*/React.createElement(FormattedMessage, {
    id: "report.commit.history"
  })), /*#__PURE__*/React.createElement(_Spin, {
    spinning: loading
  }, /*#__PURE__*/React.createElement("div", {
    className: "c7n-report-history-list"
  }, list)), /*#__PURE__*/React.createElement("div", {
    className: "c7n-report-history-page"
  }, total ? /*#__PURE__*/React.createElement(_Pagination, {
    tiny: true,
    size: "small",
    total: total || 0,
    current: pageNum || 1,
    pageSize: 5,
    showSizeChanger: false,
    onChange: onPageChange
  }) : null));
}