import "choerodon-ui/pro/lib/tooltip/style";
import _Tooltip from "choerodon-ui/pro/lib/tooltip";
import "choerodon-ui/pro/lib/table/style";
import _Table from "@hzero-front-ui/c7n-ui/lib/TablePro";
import React from 'react';
import { StatusTag, TimePopover } from '@choerodon/components';
import { observer } from 'mobx-react-lite';
import ClickText from "../../../../../../components/click-text";
import getDuration from "../../../../../../utils/getDuration";
import { useMirrorScanStore } from "./stores";
import "./index.less";
var Column = _Table.Column;

var MirrorScanning = function MirrorScanning() {
  var _useMirrorScanStore = useMirrorScanStore(),
      prefixCls = _useMirrorScanStore.prefixCls,
      detailDs = _useMirrorScanStore.detailDs,
      tableDs = _useMirrorScanStore.tableDs,
      statusMap = _useMirrorScanStore.statusMap,
      history = _useMirrorScanStore.history;

  var detailRecord = detailDs.current;

  var renderExpandRow = function renderExpandRow(_ref) {
    var dataSet = _ref.dataSet,
        record = _ref.record;
    var text = record.get('description');
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-table-describe")
    }, /*#__PURE__*/React.createElement("p", null, "\u7B80\u4ECB\uFF1A", text));
  };

  var renderStatus = function renderStatus(_ref2) {
    var value = _ref2.value,
        text = _ref2.text;

    var _ref3 = statusMap.get(text) || {},
        code = _ref3.code,
        name = _ref3.name;

    return /*#__PURE__*/React.createElement(StatusTag, {
      colorCode: code,
      type: "border",
      name: name
    });
  };

  function handleLink(vulnerabilityCode) {
    window.open("https://cve.mitre.org/cgi-bin/cvename.cgi?name=".concat(vulnerabilityCode));
  }

  var renderDetails = function renderDetails() {
    var _detailRecord$toData = detailRecord.toData(),
        startDate = _detailRecord$toData.startDate,
        spendTime = _detailRecord$toData.spendTime,
        level = _detailRecord$toData.level,
        highCount = _detailRecord$toData.highCount,
        lowCount = _detailRecord$toData.lowCount,
        mediumCount = _detailRecord$toData.mediumCount,
        unknownCount = _detailRecord$toData.unknownCount,
        criticalCount = _detailRecord$toData.criticalCount;

    var _ref4 = statusMap.get(level) || {},
        code = _ref4.code,
        name = _ref4.name;

    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail")
    }, /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-row")
    }, /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u6F0F\u6D1E\u4E25\u91CD\u5EA6\uFF1A"), code ? /*#__PURE__*/React.createElement(StatusTag, {
      colorCode: code,
      type: "border",
      name: name
    }) : '-'), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u955C\u50CF\u626B\u63CF\u5F00\u59CB\u65F6\u95F4\uFF1A"), startDate ? /*#__PURE__*/React.createElement(TimePopover, {
      content: startDate
    }) : '-'), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u955C\u50CF\u626B\u63CF\u8017\u65F6\uFF1A"), /*#__PURE__*/React.createElement("span", null, spendTime ? getDuration({
      value: spendTime,
      unit: 'ms'
    }) : '-'))), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-row")
    }, /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u5371\u6025\u6F0F\u6D1E\uFF1A"), /*#__PURE__*/React.createElement("span", null, criticalCount)), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u4E25\u91CD\u6F0F\u6D1E\uFF1A"), /*#__PURE__*/React.createElement("span", null, highCount)), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u4E2D\u7B49\u6F0F\u6D1E\uFF1A"), /*#__PURE__*/React.createElement("span", null, mediumCount)), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u8F83\u4F4E\u6F0F\u6D1E\uFF1A"), /*#__PURE__*/React.createElement("span", null, lowCount)), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content")
    }, /*#__PURE__*/React.createElement("span", null, "\u672A\u77E5\u6F0F\u6D1E\uFF1A"), /*#__PURE__*/React.createElement("span", null, unknownCount))));
  };

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls)
  }, detailRecord && renderDetails(), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-table")
  }, /*#__PURE__*/React.createElement(_Table, {
    dataSet: tableDs,
    mode: 'tree',
    queryBar: 'none',
    expandedRowRenderer: renderExpandRow
  }, /*#__PURE__*/React.createElement(Column, {
    name: "vulnerabilityCode",
    renderer: function renderer(_ref5) {
      var text = _ref5.text,
          record = _ref5.record;
      return /*#__PURE__*/React.createElement(ClickText, {
        clickAble: true,
        onClick: function onClick() {
          return handleLink(record.get('vulnerabilityCode'));
        },
        value: text,
        showToolTip: true
      });
    },
    sortable: true
  }), /*#__PURE__*/React.createElement(Column, {
    name: "severity",
    renderer: renderStatus,
    width: 100,
    sortable: true
  }), /*#__PURE__*/React.createElement(Column, {
    name: "pkgName",
    sortable: true
  }), /*#__PURE__*/React.createElement(Column, {
    name: "installedVersion",
    sortable: true,
    renderer: function renderer(_ref6) {
      var text = _ref6.text;
      return /*#__PURE__*/React.createElement(_Tooltip, {
        title: text
      }, text);
    }
  }), /*#__PURE__*/React.createElement(Column, {
    name: "fixedVersion",
    sortable: true,
    renderer: function renderer(_ref7) {
      var text = _ref7.text;
      return /*#__PURE__*/React.createElement(_Tooltip, {
        title: text
      }, text);
    }
  }))));
};

export default observer(MirrorScanning);