"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 = _interopRequireWildcard(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"));
var _olMap = require("@vtx/ol-map");
var _radio = _interopRequireDefault(require("antd/lib/radio"));
var _config = _interopRequireDefault(require("../../_mapUtil/config"));
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 && {}.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(e) { return e && e.__esModule ? e : { "default": e }; }
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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; } /* eslint-disable react/prop-types */
var prefixCls = 'ol-map-analysis-result-diagnosis';
var symbolMap = {
  '-1': _up["default"],
  '0': _current["default"],
  1: _down["default"]
};
var colorMap = {
  '-1': '#308BFA',
  '0': '#F7984C',
  1: '#00B5B4'
};
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,
    customSkeleton = _ref.customSkeleton,
    _ref$showMap = _ref.showMap,
    showMap = _ref$showMap === void 0 ? true : _ref$showMap,
    _ref$waterPipes = _ref.waterPipes,
    waterPipes = _ref$waterPipes === void 0 ? [] : _ref$waterPipes,
    _ref$upstreamItems = _ref.upstreamItems,
    upstreamItems = _ref$upstreamItems === void 0 ? [] : _ref$upstreamItems,
    _ref$downstreamItems = _ref.downstreamItems,
    downstreamItems = _ref$downstreamItems === void 0 ? [] : _ref$downstreamItems,
    _ref$targetItem = _ref.targetItem,
    targetItem = _ref$targetItem === void 0 ? {} : _ref$targetItem,
    _ref$showTitle = _ref.showTitle,
    showTitle = _ref$showTitle === void 0 ? true : _ref$showTitle;
  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 legendData = [];
  skeletonNodes.forEach(function (node) {
    var target = node.target;
    if (target === 0) {
      legendData.push({
        name: '当前设备',
        itemStyle: {
          color: colorMap[0],
          borderWidth: 0
        }
      });
    } else if (target === 1) {
      legendData.push({
        name: '上游设备',
        itemStyle: {
          color: colorMap[1],
          borderWidth: 0
        }
      });
    } else if (target === -1) {
      legendData.push({
        name: '下游设备',
        itemStyle: {
          color: colorMap[-1],
          borderWidth: 0
        }
      });
    }
  });
  var option = {
    tooltip: {},
    legend: {
      icon: 'circle',
      textStyle: {
        color: theme === 'light' ? '#2D2D2D' : '#fff',
        fontSize: 14
      },
      data: [].concat(_toConsumableArray(_lodash["default"].find(skeletonNodes, {
        target: -1
      }) ? [{
        name: '上游设备',
        itemStyle: {
          color: '#308BFA',
          borderWidth: 0
        }
      }] : []), _toConsumableArray(_lodash["default"].find(skeletonNodes, {
        target: 1
      }) ? [{
        name: '下游设备',
        itemStyle: {
          color: '#00B5B4',
          borderWidth: 0
        }
      }] : []), _toConsumableArray(_lodash["default"].find(skeletonNodes, {
        target: 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
    }]
  };
  var _useState3 = (0, _react.useState)(showMap ? 'map' : 'chart'),
    _useState4 = _slicedToArray(_useState3, 2),
    type = _useState4[0],
    setType = _useState4[1];
  var mapRef = (0, _react.useRef)();
  var createdMap = function createdMap(map) {
    mapRef.current = map;
  };
  (0, _react.useEffect)(function () {
    if (mapRef.current && !(0, _lodash.isEmpty)(waterPipes)) {
      mapRef.current.fitView(waterPipes);
    }
  }, [mapRef, waterPipes]);
  var deviceList = [];
  if (!(0, _lodash.isEmpty)(targetItem)) {
    var _device$installLocati;
    var device = targetItem.device;
    deviceList.push(_objectSpread(_objectSpread({
      target: 0
    }, device), {}, {
      geometryInfo: {
        coordType: 'wgs84',
        lngLats: device === null || device === void 0 || (_device$installLocati = device.installLocationDTO) === null || _device$installLocati === void 0 ? void 0 : _device$installLocati.lngLats,
        type: 'point'
      }
    }));
  }
  upstreamItems.forEach(function (item) {
    var _device$installLocati2;
    var device = item.device;
    deviceList.push(_objectSpread(_objectSpread({
      target: -1
    }, device), {}, {
      geometryInfo: {
        coordType: 'wgs84',
        lngLats: device === null || device === void 0 || (_device$installLocati2 = device.installLocationDTO) === null || _device$installLocati2 === void 0 ? void 0 : _device$installLocati2.lngLats,
        type: 'point'
      }
    }));
  });
  downstreamItems.forEach(function (item) {
    var _device$installLocati3;
    var device = item.device;
    deviceList.push(_objectSpread(_objectSpread({
      target: 1
    }, device), {}, {
      geometryInfo: {
        coordType: 'wgs84',
        lngLats: device === null || device === void 0 || (_device$installLocati3 = device.installLocationDTO) === null || _device$installLocati3 === void 0 ? void 0 : _device$installLocati3.lngLats,
        type: 'point'
      }
    }));
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-wrap")
  }, (!(0, _lodash.isEmpty)(skeletonNodes) || customSkeleton) && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '拓扑结构',
    rightContent: showMap ? /*#__PURE__*/_react["default"].createElement(_radio["default"].Group, {
      size: "small",
      value: type,
      onChange: function onChange(e) {
        return setType(e.target.value);
      }
    }, /*#__PURE__*/_react["default"].createElement(_radio["default"].Button, {
      value: "map"
    }, "\u5730\u56FE"), /*#__PURE__*/_react["default"].createElement(_radio["default"].Button, {
      value: "chart"
    }, "\u56FE\u8868")) : null
  }), type === 'map' && /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      margin: '16px 0',
      display: 'flex',
      flexDirection: 'column',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 8
    }
  }, (0, _lodash.unionBy)(legendData, 'name').map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
      style: {
        width: 16,
        height: 16,
        borderRadius: '50%',
        background: item.itemStyle.color
      }
    }), /*#__PURE__*/_react["default"].createElement("div", null, item.name));
  })), /*#__PURE__*/_react["default"].createElement(_olMap.Map, {
    tk: "1adbb6e47668cb33757cd799548bf1f4",
    height: 400,
    createdMap: createdMap
  }, /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: waterPipes,
    id: "RESULT_LINE",
    labelField: "code",
    style: function style(feature) {
      var color = _config["default"].gwColorMap[feature.values_.networkType];
      return {
        type: 'Polyline',
        style: {
          stroke: {
            color: color
          }
        }
      };
    }
  }), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: deviceList,
    id: "RESULT_DEVICE",
    labelField: "name",
    style: function style(feature) {
      var color = colorMap[feature.values_.target];
      return {
        type: 'Point',
        style: {
          stroke: {
            color: color,
            opacity: 1,
            width: 1
          },
          fill: {
            color: color,
            opacity: 1
          },
          radius: 7
        }
      };
    }
  }))), type === 'chart' && (customSkeleton || /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    style: {
      height: 400
    }
  }))), children, showTitle && /*#__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))), showReport && /*#__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
