"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _ResultTitle = _interopRequireDefault(require("../ResultTitle"));
require("./index.less");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _lodash = require("lodash");
var _current = _interopRequireDefault(require("./assets/current.svg"));
var _up = _interopRequireDefault(require("./assets/up.svg"));
var _down = _interopRequireDefault(require("./assets/down.svg"));
var _space = _interopRequireDefault(require("antd/lib/space"));
var _EventReportModal = _interopRequireDefault(require("../EventReportModal"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-disable react/prop-types */
var prefixCls = 'ol-map-analysis-result-diagnosis';
var symbolMap = {
  '-1': _up["default"],
  '0': _current["default"],
  1: _down["default"]
};
var ResultDiagnosis = function ResultDiagnosis(_ref) {
  var result = _ref.result,
    reason = _ref.reason,
    _ref$reasonTitle = _ref.reasonTitle,
    reasonTitle = _ref$reasonTitle === void 0 ? '诊断原因' : _ref$reasonTitle,
    _ref$showReport = _ref.showReport,
    showReport = _ref$showReport === void 0 ? true : _ref$showReport,
    measure = _ref.measure,
    _ref$skeletonNodes = _ref.skeletonNodes,
    skeletonNodes = _ref$skeletonNodes === void 0 ? [] : _ref$skeletonNodes,
    children = _ref.children,
    _ref$info = _ref.info,
    info = _ref$info === void 0 ? {} : _ref$info,
    question = _ref.question,
    reasonStr = _ref.reasonStr,
    _ref$theme = _ref.theme,
    theme = _ref$theme === void 0 ? 'light' : _ref$theme;
  var links = [];
  skeletonNodes.forEach(function (_ref2) {
    var childFacilityIds = _ref2.childFacilityIds,
      parentFacilityIds = _ref2.parentFacilityIds,
      diameter = _ref2.diameter,
      facilityId = _ref2.facilityId;
    (childFacilityIds || []).forEach(function (id) {
      if (!links.find(function (item) {
        return item.target === id && item.source === facilityId;
      })) {
        links.push({
          target: id,
          source: facilityId,
          value: diameter
        });
      }
    });
    (parentFacilityIds || []).forEach(function (id) {
      if (!links.find(function (item) {
        return item.source === id && item.target === facilityId;
      })) {
        links.push({
          target: facilityId,
          source: id,
          value: diameter
        });
      }
    });
  });
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    visible = _useState2[0],
    setVisible = _useState2[1];
  // 递归处理
  var option = {
    tooltip: {},
    legend: {
      icon: 'circle',
      textStyle: {
        color: theme === 'light' ? '#2D2D2D' : '#fff',
        fontSize: 14
      },
      data: [{
        name: '上游设备',
        itemStyle: {
          color: '#308BFA',
          borderWidth: 0
        }
      }, {
        name: '下游设备',
        itemStyle: {
          color: '#00B5B4',
          borderWidth: 0
        }
      }, {
        name: '当前设备',
        itemStyle: {
          color: '#F7984C',
          borderWidth: 0
        }
      }],
      top: '5%',
      left: 'center',
      show: true
    },
    series: [{
      categories: [{
        name: '上游设备'
      }, {
        name: '下游设备'
      }, {
        name: '当前设备'
      }],
      type: 'graph',
      layout: 'force',
      force: {
        repulsion: 1500,
        edgeLength: 120,
        layoutAnimation: true
      },
      symbolSize: 30,
      nodeScaleRatio: 1,
      //图标大小是否随鼠标滚动而变
      roam: true,
      //缩放
      draggable: true,
      //节点是否可以拖拽
      edgeSymbol: ['none', 'arrow'],
      //线2头标记

      label: {
        show: false
      },
      emphasis: {
        label: {
          show: false
        }
      },
      edgeLabel: {
        normal: {
          show: true,
          width: 58,
          height: 22,
          borderRadius: 12,
          backgroundColor: '#E1E5EA',
          align: 'center',
          verticalAlign: 'middle',
          textStyle: {
            fontSize: 12,
            color: '#2D2D2D'
          },
          formatter: '{c}mm'
        }
      },
      symbolKeepAspect: false,
      focusNodeAdjacency: false,
      // 指定的节点以及其所有邻接节点高亮
      itemStyle: {
        normal: {
          borderColor: '#29ACFC',
          borderWidth: 2,
          shadowColor: '#29ACFC',
          color: '#29ACFC',
          curveness: 0.08
        }
      },
      tooltip: {
        formatter: function formatter() {
          return '';
        }
      },
      lineStyle: {
        normal: {
          width: 2,
          curveness: 0.15,
          color: '#9DA9BA'
        }
      },
      data: skeletonNodes.map(function (_ref3) {
        var lineNo = _ref3.lineNo,
          target = _ref3.target,
          facilityId = _ref3.facilityId,
          roadName = _ref3.roadName;
        return {
          name: facilityId,
          symbol: "image://".concat(symbolMap[target]),
          tooltip: {
            formatter: "".concat(roadName || '').concat(lineNo)
          }
        };
      }),
      links: links
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-wrap")
  }, !(0, _lodash.isEmpty)(skeletonNodes) && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '拓扑结构'
  }), /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    style: {
      height: 400
    }
  })), children, /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '结果诊断',
    question: question
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-content")
  }, result && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-subtitle")
  }, "\u8BCA\u65AD\u7ED3\u679C"), /*#__PURE__*/_react["default"].createElement("div", null, result)), reason && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-subtitle")
  }, /*#__PURE__*/_react["default"].createElement("span", null, reasonTitle), showReport && /*#__PURE__*/_react["default"].createElement("a", {
    onClick: function onClick() {
      setVisible(true);
    }
  }, /*#__PURE__*/_react["default"].createElement(_space["default"], {
    align: "center"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: require('./assets/report.svg'),
    width: 16,
    height: 16
  }), "\u4E0A\u62A5"))), /*#__PURE__*/_react["default"].createElement("div", null, reason)), measure && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-subtitle")
  }, "\u5904\u7406\u63AA\u65BD"), /*#__PURE__*/_react["default"].createElement("div", null, measure))), /*#__PURE__*/_react["default"].createElement(_EventReportModal["default"], {
    visible: visible,
    onCancel: function onCancel() {
      return setVisible(false);
    },
    info: _objectSpread(_objectSpread({}, info), {}, {
      caseDesc: (0, _lodash.isString)(reason) ? reason : reasonStr
    }),
    theme: theme
  }));
};
ResultDiagnosis.propTypes = {
  result: _propTypes["default"].string,
  reason: _propTypes["default"].string,
  measure: _propTypes["default"].string,
  skeletonNodes: _propTypes["default"].array,
  reasonTitle: _propTypes["default"].string,
  showReport: _propTypes["default"].bool,
  question: _propTypes["default"].element,
  info: _propTypes["default"].object
};
var _default = exports["default"] = ResultDiagnosis;
//# sourceMappingURL=index.js.map
