"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 _react = _interopRequireWildcard(require("react"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _PublicService = _interopRequireDefault(require("../_mapUtil/PublicService"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _checkbox = _interopRequireDefault(require("antd/lib/checkbox"));
var _MyEmpty = _interopRequireDefault(require("../_component/MyEmpty"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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 _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 _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; } /**
 * 结果
 * @description: 用于展示分析结果列表、结果图层等
 */
var Result = function Result() {
  var _useProps = (0, _useProps2["default"])(),
    tableData = _useProps.tableData,
    classnames = _useProps.classnames,
    selectOptions = _useProps.selectOptions,
    facilityType = _useProps.facilityType,
    selectValue = _useProps.selectValue;
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    checked = _useState2[0],
    setChecked = _useState2[1];
  var _ref = tableData || {},
    _ref$timeList = _ref.timeList,
    timeList = _ref$timeList === void 0 ? [] : _ref$timeList;
  // 入流入渗旱季变化规律
  var handleCheckbox = function handleCheckbox(e) {
    setChecked(e.target.checked);
  };

  // 获取series数据
  var getSeriesData = function getSeriesData() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var time = arguments.length > 1 ? arguments[1] : undefined;
    var rate = arguments.length > 2 ? arguments[2] : undefined;
    var defaultArr = [];
    if (data !== null && data !== void 0 && data.length) {
      time.length && time.forEach(function (item) {
        var dataValue = data.filter(function (val) {
          return val.time === item;
        }) || [];
        if (dataValue.length) {
          if (rate && dataValue[0].value) {
            defaultArr.push(Number(dataValue[0].value) * rate);
          } else {
            defaultArr.push(dataValue[0].value);
          }
        } else {
          defaultArr.push(null);
        }
      });
    }
    return defaultArr;
  };
  // 通过边界获取新的曲线数据
  var getBorderData = function getBorderData(data, dry) {
    var newData = [];
    if (data.length && dry.length) {
      data.map(function (item, index) {
        if (item < dry[index]) {
          newData.push(item);
        } else {
          newData.push(dry[index]);
        }
      });
    }
    return newData;
  };
  // 入流入渗 （结果展示）
  var renderInflowInfiltration = function renderInflowInfiltration() {
    var _selectOptions$facili;
    var _ref2 = tableData || {},
      _ref2$rainCapacity = _ref2.rainCapacity,
      rainCapacity = _ref2$rainCapacity === void 0 ? [] : _ref2$rainCapacity,
      _ref2$timeList = _ref2.timeList,
      timeList = _ref2$timeList === void 0 ? [] : _ref2$timeList;
    var chartData = ((_selectOptions$facili = selectOptions[facilityType]) === null || _selectOptions$facili === void 0 ? void 0 : _selectOptions$facili.chartsData[selectValue]) || {};
    // 时间
    var timeData = _PublicService["default"].getDataByKey(timeList, 'time');
    var RainData = getSeriesData(rainCapacity, timeData);
    // 监测数据
    var currentData = getSeriesData(tableData[chartData.currentData] || [], timeData);

    // 旱季数据
    var dryData = getSeriesData(tableData[chartData.dryData] || [], timeData);
    var name = chartData.name || '';
    var dryName = chartData.dryName || '';
    var dryDataNew = getSeriesData(tableData[chartData.dryData] || [], timeData, 1.5);
    var borderData = getBorderData(currentData, dryDataNew);
    var option = {
      grid: {
        top: 60,
        left: 50,
        right: 50,
        bottom: 50,
        containLabel: true
      },
      legend: {
        show: true,
        itemWidth: 25,
        itemHeight: 10,
        data: [{
          name: name
        }, {
          name: '降雨量(mm)'
        }].concat(_toConsumableArray(checked ? [{
          name: dryName,
          itemStyle: {
            color: '#000000'
          }
        }] : []))
      },
      tooltip: {
        trigger: 'axis',
        axisLine: {
          lineStyle: {
            color: '#FEFEFE'
          }
        },
        confine: true,
        axisPointer: {
          type: 'cross',
          animation: false,
          label: {
            show: false,
            formatter: function formatter(params) {
              if (params.seriesData.length === 0 && params.axisIndex === 0) {
                window.mouseCurValueRlrs = params.value;
              }
            }
          },
          crossStyle: {
            opacity: 0
          }
        },
        formatter: function formatter(params) {
          var content = null;
          // 实测值
          var ddlValue = params.filter(function (item) {
            return item.seriesIndex === 1;
          }) || [];
          // 边界值
          var list2 = params.filter(function (item) {
            return item.seriesName === '边界线';
          }) || [];
          var value2 = null;
          if (list2.length) {
            value2 = list2[0].value && Number(list2[0].value);
          }
          if (ddlValue.length) {
            var value = ddlValue[0].value && Number(ddlValue[0].value);
            if (value2 && window.mouseCurValueRlrs > value2 && value > value2 && value > window.mouseCurValueRlrs) {
              content = '存在入流入渗风险';
            } else {
              var subItem = '';
              params.length && params.map(function (val, idx) {
                if (val.seriesName !== '边界线') {
                  if (idx == 0) {
                    subItem += "<div>".concat(val.axisValue, "</div>");
                  }
                  subItem += "<div>".concat(val.marker, " ").concat(val.seriesName, " ").concat(val.data || '', "</div>");
                }
              });
              content = "<div>".concat(subItem, "</div>");
            }
          } else {
            var _subItem = '';
            params.length && params.map(function (val, idx) {
              if (val.seriesName !== '边界线') {
                if (idx == 0) {
                  _subItem += "<div>".concat(val.axisValue, "</div>");
                }
                _subItem += "<div>".concat(val.marker, " ").concat(val.seriesName, " ").concat(val.data || '', "</div>");
              }
            });
            content = "<div>".concat(_subItem, "</div>");
          }
          return content;
        }
      },
      xAxis: {
        type: 'category',
        data: timeData.map(function (str) {
          return str.replace(' ', '\n');
        }),
        axisTick: {
          show: false
        },
        axisLabel: {
          color: '#000'
        }
      },
      yAxis: [{
        type: 'value',
        name: name,
        alignTicks: true,
        axisLine: {
          show: true
        }
      }, {
        type: 'value',
        name: '降雨量(mm)',
        nameLocation: 'start',
        alignTicks: true,
        inverse: true,
        axisLine: {
          show: true
        }
      }],
      dataZoom: [{
        // 这个dataZoom组件，默认控制x轴。
        type: 'slider',
        // 这个 dataZoom 组件是 slider 型 dataZoom 组件
        start: 0,
        // 左边在 10% 的位置。
        end: 100,
        // 右边在 60% 的位置。
        button: '15%',
        fillerColor: 'rgba(97, 212, 225, 0.35)',
        borderColor: 'none',
        handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
        handleSize: '150%',
        height: 10,
        handleStyle: {
          color: '#fff',
          shadowBlur: 3,
          shadowColor: 'rgba(0, 0, 0, 0.4)',
          shadowOffsetX: 2,
          shadowOffsetY: 2
        },
        showDataShadow: false,
        showDetail: false,
        bottom: 14
      }, {
        // 这个dataZoom组件，也控制x轴。
        type: 'inside',
        // 这个 dataZoom 组件是 inside 型 dataZoom 组件
        start: 0,
        // 左边在 10% 的位置。
        end: 100,
        // 右边在 60% 的位置。
        height: 10,
        bottom: 14
      }],
      series: [{
        data: RainData,
        type: 'bar',
        name: '降雨量(mm)',
        yAxisIndex: 1,
        barMaxWidth: 25,
        barMinWidth: 12,
        symbol: 'none',
        itemStyle: {
          color: '#b1da9d'
        }
      }, {
        data: currentData,
        type: 'line',
        name: name,
        areaStyle: {
          color: checked ? '#ec808d' : '#869ad6',
          opacity: 1
        },
        lineStyle: {
          opacity: 0
        },
        symbol: 'none',
        connectNulls: true,
        emphasis: {
          disabled: true
        },
        smooth: true
      }].concat(_toConsumableArray(checked ? [{
        name: dryName,
        data: dryData,
        type: 'line',
        connectNulls: true,
        lineStyle: {
          color: '#000000'
        },
        itemStyle: {
          color: '#000000',
          opacity: 0
        },
        symbol: 'none',
        emphasis: {
          disabled: true
        },
        smooth: true
      }, {
        name: '边界线',
        data: borderData,
        type: 'line',
        connectNulls: true,
        areaStyle: {
          color: '#869ad6',
          opacity: 1
        },
        lineStyle: {
          opacity: 0
        },
        symbol: 'none',
        emphasis: {
          disabled: true
        },
        smooth: true
      }] : []))
    };
    return /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
      style: {
        height: 230
      },
      option: option,
      notMerge: true,
      lazyUpdate: true
    });
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('contentWarp')
  }, timeList !== null && timeList !== void 0 && timeList.length ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
    checked: checked,
    onChange: handleCheckbox
  }, "\u65F1\u5B63\u53D8\u5316\u89C4\u5F8B"), renderInflowInfiltration()) : /*#__PURE__*/_react["default"].createElement(_MyEmpty["default"], {
    type: "charts"
  }));
};
var _default = exports["default"] = Result;
//# sourceMappingURL=Result.js.map
