"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 _vtxModal = _interopRequireDefault(require("@vtx/components/lib/vtx-modal"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _col = _interopRequireDefault(require("antd/lib/col"));
var _row = _interopRequireDefault(require("antd/lib/row"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _GwDetail = _interopRequireDefault(require("../_component/GwDetail"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var echarts = _interopRequireWildcard(require("echarts"));
var _moment = _interopRequireDefault(require("moment"));
var _lodash = require("lodash");
var _ResultDiagnosis = _interopRequireDefault(require("../_component/ResultDiagnosis"));
var _AnalysisDetailWrap = _interopRequireDefault(require("../_component/AnalysisDetailWrap"));
var _useGetDeviceData2 = _interopRequireDefault(require("../_mapUtil/useGetDeviceData"));
var _StreamInfoWrap = _interopRequireDefault(require("../_component/StreamInfoWrap"));
var _config = require("./config");
var _AnalysisDetailStatistics = _interopRequireDefault(require("../_component/AnalysisDetailStatistics"));
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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 _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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
// eslint-disable-next-line react/prop-types
var DeviceMonitor = function DeviceMonitor(_ref) {
  var _data$find, _data$find2;
  var _ref$config = _ref.config,
    config = _ref$config === void 0 ? {} : _ref$config,
    deviceFacilityId = _ref.deviceFacilityId,
    sedimentationType = _ref.sedimentationType,
    startDate = _ref.startDate,
    endDate = _ref.endDate,
    diameter = _ref.diameter;
  var startTime = (0, _react.useMemo)(function () {
    return (0, _moment["default"])(startDate).subtract(24, 'h').valueOf();
  }, [startDate]);
  var endTime = (0, _react.useMemo)(function () {
    return (0, _moment["default"])(endDate).add(24, 'h').valueOf();
  }, [endDate]);
  var _useGetDeviceData = (0, _useGetDeviceData2["default"])({
      monitorItemCodes: 'w_liquid_level,w_speed_now',
      facilityId: deviceFacilityId,
      startTime: startTime,
      endTime: endTime
    }),
    _useGetDeviceData$dat = _useGetDeviceData.data,
    data = _useGetDeviceData$dat === void 0 ? [] : _useGetDeviceData$dat;
  var ywData = ((_data$find = data.find(function (item) {
    return item.monitorItemCode === 'w_liquid_level';
  })) === null || _data$find === void 0 ? void 0 : _data$find.values) || [];
  var lsData = ((_data$find2 = data.find(function (item) {
    return item.monitorItemCode === 'w_speed_now';
  })) === null || _data$find2 === void 0 ? void 0 : _data$find2.values) || [];
  var option = {
    grid: {
      top: '20%',
      left: '5%',
      right: '10%',
      bottom: '20%',
      containLabel: true
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      left: 'center',
      top: 30,
      itemWidth: 18,
      itemHeight: 6,
      itemGap: 32,
      textStyle: {
        color: '#222',
        fontSize: 14
      },
      data: [{
        name: '液位'
      }, {
        name: '流速'
      }, {
        name: '液位上限',
        itemStyle: {
          opacity: 0
        }
      }, {
        name: '流速下限',
        itemStyle: {
          opacity: 0
        }
      }]
    },
    xAxis: {
      type: 'category',
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: true,
        textStyle: {
          fontSize: 12,
          color: 'rgba(0, 0, 0, 0.6)' //X轴文字颜色
        },
        formatter: function formatter(value) {
          return value.replace(' ', '\n');
        }
      }
    },
    yAxis: ['液位（m）', '流速（m/s）'].map(function (key) {
      return {
        type: 'value',
        name: key,
        nameTextStyle: {
          color: 'rgba(0, 0, 0, 0.6)',
          fontSize: 12
        },
        axisLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          color: 'rgba(0, 0, 0, 0.6)',
          fontSize: 14
        },
        splitLine: {
          show: true,
          lineStyle: {
            color: 'rgba(0, 0, 0, 0.2)',
            type: 'dashed'
          }
        }
      };
    }),
    dataZoom: [{}],
    series: [].concat(_toConsumableArray(['液位', '流速'].map(function (name, index) {
      var color = '#00DC77';
      var areaColor = 'rgba(0, 220, 119, 0.7)';
      var areaColor1 = 'rgba(0, 220, 119, 0)';
      var newData = ywData;
      if (name === '流速') {
        color = '#FF8D2C';
        areaColor = 'rgba(255, 141, 44, 0.7)';
        areaColor1 = 'rgba(255, 141, 44, 0)';
        newData = lsData;
      }
      newData = newData.map(function (item) {
        return [(0, _moment["default"])(item.x).format('MM-DD HH:mm'), item.y];
      });
      return {
        yAxisIndex: index,
        name: name,
        type: 'line',
        smooth: true,
        symbol: 'circle',
        //标记的图形为实心圆
        symbolSize: 6,
        //标记的大小
        itemStyle: {
          //折线拐点标志的样式
          color: 'white',
          borderWidth: '1',
          borderColor: color
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          // 折线点的阴影
          {
            offset: 0,
            color: areaColor1
          }, {
            offset: 1,
            color: areaColor
          }])
        },
        lineStyle: {
          color: color
        },
        data: newData
      };
    })), _toConsumableArray(['液位上限', '流速下限'].map(function (name, index) {
      var color = name === '流速下限' ? '#CB4EFF' : '#FF3A3A';
      var newData = (0, _lodash.isEmpty)(ywData) ? lsData : ywData;
      var highThroughWaterLevelRatio = config.highThroughWaterLevelRatio,
        waterLevelRatio = config.waterLevelRatio,
        highThroughFlowSpeed = config.highThroughFlowSpeed,
        lowFlowSpeed = config.lowFlowSpeed;
      var levelRatio = waterLevelRatio;
      var flowSpeed = lowFlowSpeed;
      if (sedimentationType === _config.SedimentationType.GTGD) {
        levelRatio = highThroughWaterLevelRatio;
        flowSpeed = highThroughFlowSpeed;
      }
      var value = name === '流速下限' ? flowSpeed : (levelRatio * diameter / 1000).toFixed(2);
      newData = newData.map(function (item) {
        return [(0, _moment["default"])(item.x).format('MM-DD HH:mm'), value];
      });
      return {
        yAxisIndex: index,
        name: name,
        type: 'line',
        symbol: 'none',
        //标记的图形为实心圆
        lineStyle: {
          color: color,
          type: 'dashed'
        },
        data: newData
      };
    })))
  };
  return /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    style: {
      width: '100%',
      height: 280
    },
    option: option
  });
};

// eslint-disable-next-line react/prop-types
var Analysis = function Analysis(_ref2) {
  var _info$result;
  var _ref2$info = _ref2.info,
    info = _ref2$info === void 0 ? {} : _ref2$info;
  var avgWaterLevel = info.avgWaterLevel,
    avgFlowSpeed = info.avgFlowSpeed,
    durationHour = info.durationHour,
    sedimentationType = info.sedimentationType,
    endDate = info.endDate,
    startDate = info.startDate,
    diameter = info.diameter;
  var list = [].concat(_toConsumableArray(sedimentationType !== _config.SedimentationType.ZC ? [{
    label: '淤积时长',
    value: durationHour,
    unit: 'h',
    icon: require('./assets/duration.svg')
  }] : []), [{
    label: [_config.SedimentationType.ZC, _config.SedimentationType.GTGD].includes(sedimentationType) ? '平均液位' : '淤积时段平均液位',
    value: avgWaterLevel,
    unit: 'm',
    icon: require('./assets/yw.svg'),
    color: '#00b767'
  }, {
    label: [_config.SedimentationType.ZC, _config.SedimentationType.GTGD].includes(sedimentationType) ? '平均流速' : '淤积时段平均流速',
    value: avgFlowSpeed,
    unit: 'm/s',
    icon: require('./assets/ls.svg'),
    color: '#ff7200'
  }]);
  return /*#__PURE__*/_react["default"].createElement(_AnalysisDetailWrap["default"], {
    roadName: info.roadName,
    lineNo: info.lineNo,
    header: '淤积分析'
  }, /*#__PURE__*/_react["default"].createElement(_AnalysisDetailStatistics["default"], {
    list: list
  }), /*#__PURE__*/_react["default"].createElement(DeviceMonitor, {
    config: info === null || info === void 0 || (_info$result = info.result) === null || _info$result === void 0 ? void 0 : _info$result.config,
    info: info,
    deviceFacilityId: info.deviceFacilityId,
    sedimentationType: info.sedimentationType,
    startDate: startDate,
    endDate: endDate,
    diameter: diameter
  }));
};

// eslint-disable-next-line react/prop-types
var StreamInfo = function StreamInfo(_ref3) {
  var _ref3$info = _ref3.info,
    info = _ref3$info === void 0 ? {} : _ref3$info,
    isUp = _ref3.isUp,
    _ref3$config = _ref3.config,
    config = _ref3$config === void 0 ? {} : _ref3$config;
  var sedimentationType = info.sedimentationType,
    deviceFacilityId = info.deviceFacilityId,
    lineNo = info.lineNo,
    startDate = info.startDate,
    endDate = info.endDate,
    diameter = info.diameter;
  var isError = sedimentationType !== _config.SedimentationType.ZC;
  return /*#__PURE__*/_react["default"].createElement(_StreamInfoWrap["default"], {
    isError: isError,
    isUp: isUp,
    lineNo: lineNo
  }, /*#__PURE__*/_react["default"].createElement(DeviceMonitor, {
    config: config,
    deviceFacilityId: deviceFacilityId,
    sedimentationType: sedimentationType,
    startDate: startDate,
    diameter: diameter,
    endDate: endDate
  }));
};
var DetailModal = function DetailModal(_ref4) {
  var _info$facility;
  var visible = _ref4.visible,
    info = _ref4.info,
    onCancel = _ref4.onCancel;
  var _info$result2 = info.result,
    result = _info$result2 === void 0 ? {} : _info$result2,
    sedimentationType = info.sedimentationType,
    startDate = info.startDate,
    endDate = info.endDate,
    lineNo = info.lineNo,
    durationHour = info.durationHour,
    roadName = info.roadName,
    diameter = info.diameter;
  var upstreamItems = result.upstreamItems,
    downstreamItems = result.downstreamItems,
    _result$config = result.config,
    config = _result$config === void 0 ? {} : _result$config,
    skeletonNodes = result.skeletonNodes,
    targetItem = result.targetItem;
  var longTermHandleMeasure = config.longTermHandleMeasure,
    burstHandleMeasure = config.burstHandleMeasure,
    waterLevelRatio = config.waterLevelRatio,
    lowFlowSpeed = config.lowFlowSpeed,
    highThroughHandleMeasure = config.highThroughHandleMeasure,
    highThroughWaterLevelRatio = config.highThroughWaterLevelRatio,
    highThroughFlowSpeed = config.highThroughFlowSpeed;
  var measureConfig = {
    1: burstHandleMeasure,
    2: longTermHandleMeasure,
    4: highThroughHandleMeasure
  };
  var _startDate = (0, _moment["default"])(startDate).format('YYYY-MM-DD HH:mm:ss');
  var _endDate = (0, _moment["default"])(endDate).format('YYYY-MM-DD HH:mm:ss');
  var reason = (0, _react.useMemo)(function () {
    var reason = '';
    if ([_config.SedimentationType.TFDS, _config.SedimentationType.CQYJ].includes(sedimentationType)) {
      var getCommonText = function getCommonText(lineNo, roadName) {
        return "".concat(roadName || '', " ").concat(lineNo, "\u5728").concat(_startDate, "\u81F3").concat(_endDate, "\u671F\u95F4\uFF0C");
      };
      var getErrorText = function getErrorText(_ref5) {
        var levelRatio = _ref5.levelRatio,
          flowSpeed = _ref5.flowSpeed,
          durationHour = _ref5.durationHour,
          diameter = _ref5.diameter;
        return "\u6DB2\u4F4D\u9AD8\u4E8E".concat((levelRatio * diameter / 1000).toFixed(2), "m\u4E14\u6D41\u901F\u4F4E\u4E8E").concat(flowSpeed, "m/s\u7684\u65F6\u957F\u8FBE").concat(durationHour, "h");
      };
      if ((0, _lodash.isEmpty)(upstreamItems) && (0, _lodash.isEmpty)(downstreamItems)) {
        reason = "".concat(getCommonText(lineNo, roadName)).concat(getErrorText({
          levelRatio: waterLevelRatio,
          flowSpeed: lowFlowSpeed,
          durationHour: durationHour,
          diameter: diameter
        }), "\uFF0C\u6545").concat(roadName || '', " ").concat(lineNo, "\u53EF\u80FD\u5B58\u5728").concat(sedimentationType === _config.SedimentationType.CQYJ ? '长期淤积' : '突发堵塞', "\u98CE\u9669");
      } else {
        reason = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", null, "1\u3001", "".concat(getCommonText(lineNo, roadName)).concat(getErrorText({
          levelRatio: waterLevelRatio,
          flowSpeed: lowFlowSpeed,
          durationHour: durationHour,
          diameter: diameter
        }))), [].concat(_toConsumableArray((upstreamItems || []).map(function (item) {
          return _objectSpread(_objectSpread({}, item), {}, {
            isUp: true
          });
        })), _toConsumableArray((downstreamItems || []).map(function (item) {
          return _objectSpread(_objectSpread({}, item), {}, {
            isUp: false
          });
        }))).map(function (_ref6, index) {
          var facilityId = _ref6.facilityId,
            sedimentationType = _ref6.sedimentationType,
            isUp = _ref6.isUp,
            lineNo = _ref6.lineNo,
            diameter = _ref6.diameter,
            roadName = _ref6.roadName;
          var text = "\u6DB2\u4F4D\u6D41\u901F\u5747\u4F4D\u4E8E\u6B63\u5E38\u533A\u95F4";
          if (sedimentationType !== _config.SedimentationType.ZC) {
            var levelRatio = waterLevelRatio;
            var flowSpeed = lowFlowSpeed;
            if (sedimentationType === _config.SedimentationType.GTGD) {
              levelRatio = highThroughWaterLevelRatio;
              flowSpeed = highThroughFlowSpeed;
            }
            text = getErrorText({
              levelRatio: levelRatio,
              flowSpeed: flowSpeed,
              durationHour: durationHour,
              diameter: diameter
            });
          }
          return /*#__PURE__*/_react["default"].createElement("div", {
            key: facilityId
          }, "".concat(index + 2, "\u3001").concat(isUp ? '上游节点' : '下游节点', "\uFF1A").concat(getCommonText(lineNo, roadName)).concat(text));
        }), /*#__PURE__*/_react["default"].createElement("div", null, "\u6545\u53EF\u80FD\u5B58\u5728".concat(sedimentationType === _config.SedimentationType.CQYJ ? '长期淤积' : '突发堵塞', "\u7684\u662F").concat((targetItem === null || targetItem === void 0 ? void 0 : targetItem.roadName) || '', " ").concat(targetItem === null || targetItem === void 0 ? void 0 : targetItem.lineNo, "\u7BA1\u6BB5\u3002")));
      }
    } else if (sedimentationType === _config.SedimentationType.GTGD) {
      reason = "".concat(_startDate, "\u81F3").concat(_endDate, "\u671F\u95F4\uFF0C\u6DB2\u4F4D\u4F4E\u4E8E").concat((highThroughWaterLevelRatio * diameter / 1000).toFixed(2), "m\u4E14\u6D41\u901F\u9AD8\u4E8E").concat(highThroughFlowSpeed, "\uFF0C\u6545").concat(roadName || '', " ").concat(lineNo, "\u53EF\u80FD\u5904\u4E8E\u9AD8\u901A\u72B6\u6001");
    }
    return reason;
  }, []);
  return /*#__PURE__*/_react["default"].createElement(_vtxModal["default"], {
    title: /*#__PURE__*/_react["default"].createElement(_vtxModal["default"].Title, {
      text: "\u6DE4\u79EF\u5835\u585E\u5206\u6790 >",
      subtitle: "\u8BE6\u60C5"
    }),
    width: 1366,
    footer: /*#__PURE__*/_react["default"].createElement(_button["default"], {
      onClick: onCancel
    }, "\u5173\u95ED"),
    visible: visible,
    onCancel: onCancel
  }, /*#__PURE__*/_react["default"].createElement(_row["default"], {
    gutter: [24, 0]
  }, /*#__PURE__*/_react["default"].createElement(_col["default"], {
    span: 16
  }, /*#__PURE__*/_react["default"].createElement(_GwDetail["default"], {
    id: info === null || info === void 0 || (_info$facility = info.facility) === null || _info$facility === void 0 ? void 0 : _info$facility.id
  }), /*#__PURE__*/_react["default"].createElement(Analysis, {
    info: info
  }), (0, _lodash.isEmpty)(upstreamItems) ? null : upstreamItems.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(StreamInfo, {
      info: item,
      isUp: true,
      key: item.deviceFacilityId,
      config: config
    });
  }), (0, _lodash.isEmpty)(downstreamItems) ? null : downstreamItems.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(StreamInfo, {
      info: item,
      isUp: false,
      key: item.deviceFacilityId,
      config: config
    });
  })), /*#__PURE__*/_react["default"].createElement(_col["default"], {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_ResultDiagnosis["default"], {
    result: sedimentationType === _config.SedimentationType.ZC ? "".concat(_startDate, "\u81F3").concat(_endDate, "\u671F\u95F4\uFF0C\u6DB2\u4F4D\u3001\u6D41\u901F\u5747\u4F4D\u4E8E\u6B63\u5E38\u533A\u95F4\uFF0C\u6545\u8BE5\u7BA1\u6BB5\u6B63\u5E38") : '',
    reason: reason,
    measure: measureConfig[sedimentationType],
    skeletonNodes: skeletonNodes
  }))));
};
DetailModal.propTypes = {
  visible: _propTypes["default"].bool,
  info: _propTypes["default"].object,
  onCancel: _propTypes["default"].func
};
var _default = exports["default"] = DetailModal;
//# sourceMappingURL=DetailModal.js.map
