import "choerodon-ui/pro/lib/icon/style";
import _Icon from "choerodon-ui/pro/lib/icon";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/* eslint-disable */
import React, { useEffect, Fragment, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { withRouter, Link } from 'react-router-dom';
import _ from 'lodash';
import classNames from 'classnames';
import { Page } from '@choerodon/boot';
import EmptyPage from "../../../../../components/empty-page";
import Loading from "../../../../../components/loading";
import Percentage from "../../../../../components/percentage/Percentage";
import Rating from "../../../../../components/rating/Rating";
import { QUALITY_LIST, OBJECT_TYPE } from "./components/Constants";
import { useCodeQualityStore } from "./stores";
import { useCodeManagerStore } from "../../../stores";
import NewEmptyPage from "../../../components/empty-page";
import "./index.less";
export default withRouter(observer(function (props) {
  var codeQualityStore = useCodeQualityStore();
  var formatMessage = codeQualityStore.formatMessage,
      handleMapStore = codeQualityStore.handleMapStore,
      projectId = codeQualityStore.projectId,
      codeQuality = codeQualityStore.codeQuality;

  var _useCodeManagerStore = useCodeManagerStore(),
      appServiceDs = _useCodeManagerStore.appServiceDs,
      selectAppDs = _useCodeManagerStore.selectAppDs;

  var appServiceId = selectAppDs.current.get('appServiceId');
  useEffect(function () {
    handleMapStore.setCodeQuality({
      refresh: refresh
    });
  }, [projectId, appServiceId]);

  var refresh = function refresh() {
    codeQuality.loadCodeQualityData(projectId, appServiceId);
  };

  var search = props.location.search,
      styles = props.styles;

  function getDetail() {
    if (codeQuality.getIsEmpty) {
      return /*#__PURE__*/React.createElement(NewEmptyPage, {
        title: formatMessage({
          id: 'empty.title.prohibited'
        }),
        describe: formatMessage({
          id: 'empty.title.code'
        }),
        btnText: formatMessage({
          id: 'empty.link.code'
        }),
        pathname: "/rducm/code-lib-management/apply"
      });
    }

    var _ref = codeQuality.data || {},
        date = _ref.date,
        status = _ref.status,
        sonarContents = _ref.sonarContents; // 合并数据，生成{key, value, icon, url, rate, hasReport}对象数组


    var qualityList = [];

    _.map(QUALITY_LIST, function (item) {
      var data = _.find(sonarContents, function (_ref2) {
        var key = _ref2.key;
        return item.key === key;
      }) || {};
      qualityList.push(_objectSpread(_objectSpread({}, item), data));
    });

    var quality = {
      reliability: qualityList.slice(0, 4),
      maintainability: qualityList.slice(4, 8),
      coverage: qualityList.slice(8, 11),
      duplications: qualityList.slice(11, 14)
    };
    return date || status ? /*#__PURE__*/React.createElement("div", {
      className: "c7n-codeQuality-content"
    }, /*#__PURE__*/React.createElement("div", {
      className: "c7n-codeQuality-content-head"
    }, /*#__PURE__*/React.createElement("span", {
      className: "codeQuality-head-title"
    }, formatMessage({
      id: 'codeQuality.content.title'
    })), /*#__PURE__*/React.createElement("span", {
      className: "codeQuality-head-status codeQuality-head-status-".concat(status)
    }, formatMessage({
      id: "codeQuality.status.".concat(status)
    })), /*#__PURE__*/React.createElement("span", {
      className: "codeQuality-head-date"
    }, formatMessage({
      id: 'codeQuality.analysis'
    }), "\uFF1A", date.split('+')[0].replace(/T/g, ' '))), _.map(quality, function (value, objKey) {
      return /*#__PURE__*/React.createElement("div", {
        className: "c7n-codeQuality-detail",
        key: objKey
      }, /*#__PURE__*/React.createElement("div", {
        className: "codeQuality-detail-title"
      }, formatMessage({
        id: "codeQuality.detail.".concat(objKey)
      })), /*#__PURE__*/React.createElement("div", {
        className: "codeQuality-detail-content"
      }, _.map(value, function (_ref3) {
        var icon = _ref3.icon,
            key = _ref3.key,
            hasReport = _ref3.hasReport,
            isPercent = _ref3.isPercent,
            innerValue = _ref3.value,
            rate = _ref3.rate,
            url = _ref3.url;
        return /*#__PURE__*/React.createElement("div", {
          className: "detail-content-block",
          key: key
        }, /*#__PURE__*/React.createElement(_Icon, {
          type: icon
        }), /*#__PURE__*/React.createElement("span", {
          className: "detail-content-block-title"
        }, formatMessage({
          id: "codeQuality.".concat(key)
        }), "\uFF1A"), url ? /*#__PURE__*/React.createElement("a", {
          href: url,
          target: "_blank",
          rel: "nofollow me noopener noreferrer"
        }, /*#__PURE__*/React.createElement("span", {
          className: "block-number-link"
        }, innerValue.match(/\d+(\.\d+)?/g)), /*#__PURE__*/React.createElement("span", {
          className: "block-number-percentage"
        }, innerValue.replace(/\d+(\.\d+)?/g, '')), isPercent && /*#__PURE__*/React.createElement("span", {
          className: "block-number-percentage"
        }, "%")) : /*#__PURE__*/React.createElement("span", {
          className: "block-number ".concat(!innerValue && 'block-number-noValue')
        }, innerValue || formatMessage({
          id: 'nodata'
        })), rate && key !== 'duplicated_lines_density' && /*#__PURE__*/React.createElement(Rating, {
          rating: rate
        }), key === 'coverage' && /*#__PURE__*/React.createElement(Percentage, {
          data: Number(innerValue)
        }), key === 'duplicated_lines_density' && /*#__PURE__*/React.createElement(Rating, {
          rating: rate,
          size: "18px",
          type: "pie"
        }), hasReport && /*#__PURE__*/React.createElement(Link, {
          to: {
            pathname: '/rdqam/report/code-quality-workplace',
            search: search,
            state: {
              appId: appServiceId,
              type: OBJECT_TYPE[objKey]
            }
          }
        }, /*#__PURE__*/React.createElement(_Icon, {
          type: "timeline",
          className: "reports-icon"
        })));
      })));
    })) : /*#__PURE__*/React.createElement(EmptyPage, {
      title: formatMessage({
        id: 'codeQuality.empty.title'
      }),
      describe: formatMessage({
        id: 'codeQuality.empty.content'
      }),
      access: true
    });
  }

  return /*#__PURE__*/React.createElement(Page, {
    className: classNames('c7n-region', 'c7n-codeQuality-wrapper', 'page-container', styles === null || styles === void 0 ? void 0 : styles['c7n-branch-theme4-page']),
    service: []
  }, appServiceDs.status !== 'ready' || codeQuality.loading ? /*#__PURE__*/React.createElement(Loading, {
    display: true
  }) : getDetail());
}));