import "choerodon-ui/lib/tooltip/style";
import _Tooltip from "choerodon-ui/lib/tooltip";
import "choerodon-ui/pro/lib/table/style";
import _Table from "@hzero-front-ui/c7n-ui/lib/TablePro";
import React from 'react';
import TimePopover from "../../../../../../components/time-popover";
import SyncSituation from "./SyncSituation";
import { useResourceStore } from "../../../../stores";
import { useEnvironmentStore } from "../stores";
import Tips from "../../../../../../components/new-tips";
import "./index.less";
var Column = _Table.Column;
export default function Situation() {
  var _useResourceStore = useResourceStore(),
      prefixCls = _useResourceStore.prefixCls,
      intlPrefix = _useResourceStore.intlPrefix,
      formatMessage = _useResourceStore.intl.formatMessage;

  var _useEnvironmentStore = useEnvironmentStore(),
      gitopsLogDs = _useEnvironmentStore.gitopsLogDs;

  function renderMsg(_ref) {
    var value = _ref.value;
    return /*#__PURE__*/React.createElement(_Tooltip, {
      title: value,
      placement: "topLeft"
    }, value);
  }

  function renderFileLink(_ref2) {
    var record = _ref2.record;
    var url = record.get('fileUrl');
    var path = record.get('filePath');
    return /*#__PURE__*/React.createElement("a", {
      href: url,
      target: "_blank",
      rel: "nofollow me noopener noreferrer"
    }, /*#__PURE__*/React.createElement("span", null, path));
  }

  function renderCommit(_ref3) {
    var record = _ref3.record;
    var url = record.get('commitUrl');
    var commit = record.get('commit');
    return /*#__PURE__*/React.createElement("a", {
      href: url,
      target: "_blank",
      rel: "nofollow me noopener noreferrer"
    }, /*#__PURE__*/React.createElement("span", null, commit));
  }

  function renderTime(_ref4) {
    var value = _ref4.value;
    return /*#__PURE__*/React.createElement(TimePopover, {
      datetime: value
    });
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-environment-sync")
  }, /*#__PURE__*/React.createElement(SyncSituation, null), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-environment-sync-table-title")
  }, /*#__PURE__*/React.createElement(Tips, {
    title: formatMessage({
      id: "".concat(intlPrefix, ".environment.error.logs")
    }),
    helpText: formatMessage({
      id: "".concat(intlPrefix, ".environment.error.tips")
    })
  })), /*#__PURE__*/React.createElement(_Table, {
    locale: {
      emptyText: formatMessage({
        id: 'c7ncd.env.sync.empty'
      })
    },
    dataSet: gitopsLogDs,
    border: false,
    queryBar: "none"
  }, /*#__PURE__*/React.createElement(Column, {
    name: "error",
    renderer: renderMsg
  }), /*#__PURE__*/React.createElement(Column, {
    name: "filePath",
    renderer: renderFileLink
  }), /*#__PURE__*/React.createElement(Column, {
    name: "commit",
    renderer: renderCommit
  }), /*#__PURE__*/React.createElement(Column, {
    name: "lastUpdateDate",
    sortable: true,
    renderer: renderTime,
    width: 105
  })));
}