"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 _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _MyModal = _interopRequireDefault(require("../_component/MyModal"));
var _DeviceDetail = _interopRequireDefault(require("../_component/DeviceDetail"));
var _HistoryRainSelect = _interopRequireDefault(require("../_component/HistoryRainSelect"));
var _AnalysisDetailWrap = _interopRequireDefault(require("../_component/AnalysisDetailWrap"));
var _DetailModal = require("./DetailModal");
var _lodash = _interopRequireWildcard(require("lodash"));
var _antd = require("antd");
var _config = require("./config");
var _excluded = ["visible", "id", "onCancel", "theme", "gwList"];
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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
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 Analysis = function Analysis(_ref) {
  var rainId = _ref.rainId,
    setRainList = _ref.setRainList,
    setRainId = _ref.setRainId,
    theme = _ref.theme,
    rainItem = _ref.rainItem,
    gwList = _ref.gwList;
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    activeKey = _useState2[0],
    setActiveKey = _useState2[1];
  (0, _react.useEffect)(function () {
    if (!(0, _lodash.isEmpty)(gwList)) {
      setActiveKey(gwList[0].lineNo);
    }
  }, [gwList]);
  var info = gwList.find(function (item) {
    return item.lineNo === activeKey;
  }) || {};
  var infiltrationType = info.infiltrationType,
    result = info.result,
    influenceHour = info.influenceHour,
    sunnyAvgFlow = info.sunnyAvgFlow,
    sunnyAvgWaterLevel = info.sunnyAvgWaterLevel,
    rainyAvgFlow = info.rainyAvgFlow,
    rainyAvgWaterLevel = info.rainyAvgWaterLevel,
    flowRatio = info.flowRatio,
    waterLevelRatio = info.waterLevelRatio,
    deviceFacilityId = info.deviceFacilityId;
  var _ref2 = (result === null || result === void 0 ? void 0 : result.config) || {},
    infiltrationFlowThreshold = _ref2.infiltrationFlowThreshold,
    infiltrationWaterLevelThreshold = _ref2.infiltrationWaterLevelThreshold;
  var color = '#fff2e2';
  var color1 = '#E5F6FA';
  var color2 = '#E4F4FF';
  if (theme === 'dark') {
    color = 'rgba(255, 141, 0, 0.10)';
    color1 = 'rgba(0, 238, 255, 0.10)';
    color2 = 'rgba(0, 157, 255, 0.10)';
  }
  var list = [{
    label: '晴天平均液位',
    value: sunnyAvgWaterLevel,
    unit: 'm',
    img: require('./assets/sunny.png'),
    bgColor: color
  }, {
    label: '雨天平均液位',
    value: rainyAvgWaterLevel,
    img: require('./assets/rain.png'),
    unit: 'm',
    bgColor: color1
  }, {
    label: '比值',
    value: waterLevelRatio,
    img: require('./assets/ratio.png'),
    bgColor: color2,
    isError: waterLevelRatio && infiltrationType !== _config.InfiltrationType.ZC ? waterLevelRatio > infiltrationWaterLevelThreshold : false
  }, {
    label: '晴天平均流量',
    value: sunnyAvgFlow,
    img: require('./assets/sunny.png'),
    unit: 'm³/h',
    bgColor: color
  }, {
    label: '雨天平均流量',
    value: rainyAvgFlow,
    img: require('./assets/rain.png'),
    bgColor: color1,
    unit: 'm³/h'
  }, {
    label: '比值',
    value: flowRatio,
    img: require('./assets/ratio.png'),
    bgColor: color2,
    isError: flowRatio && infiltrationType !== _config.InfiltrationType.ZC ? flowRatio > infiltrationFlowThreshold : false
  }];
  return /*#__PURE__*/_react["default"].createElement(_AnalysisDetailWrap["default"], {
    header: '入流入渗分析',
    extra: /*#__PURE__*/_react["default"].createElement(_HistoryRainSelect["default"], {
      value: rainId,
      setList: setRainList,
      onChange: function onChange(e) {
        return setRainId(e);
      },
      dropdownMatchSelectWidth: false,
      style: {
        width: '100%'
      },
      getPopupContainer: function getPopupContainer(triggerNode) {
        return triggerNode;
      }
    })
  }, /*#__PURE__*/_react["default"].createElement(_antd.Tabs, {
    size: "small",
    activeKey: activeKey,
    onChange: function onChange(key) {
      return setActiveKey(key);
    }
  }, gwList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_antd.Tabs.TabPane, {
      key: item.lineNo,
      tab: item.lineNo
    });
  })), /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [20, 10]
  }, list.map(function (_ref3, index) {
    var label = _ref3.label,
      value = _ref3.value,
      img = _ref3.img,
      bgColor = _ref3.bgColor,
      unit = _ref3.unit,
      isError = _ref3.isError;
    return /*#__PURE__*/_react["default"].createElement(_antd.Col, {
      key: index,
      span: 8
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "ol-map-analysis-infiltration-modal-analysis-item",
      style: {
        background: bgColor
      }
    }, /*#__PURE__*/_react["default"].createElement(_antd.Space, {
      align: "center"
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: img,
      width: 20,
      height: 20
    }), label), value ? /*#__PURE__*/_react["default"].createElement("span", {
      style: {
        color: isError ? '#FF1C1C' : ''
      }
    }, "".concat(value).concat(unit || '')) : '-'));
  })), /*#__PURE__*/_react["default"].createElement(_DetailModal.DeviceMonitor, {
    deviceFacilityId: deviceFacilityId,
    rainItem: rainItem,
    influenceHour: influenceHour,
    theme: theme
  }));
};
var DeviceModal = function DeviceModal(_ref4) {
  var visible = _ref4.visible,
    id = _ref4.id,
    onCancel = _ref4.onCancel,
    _ref4$theme = _ref4.theme,
    theme = _ref4$theme === void 0 ? 'light' : _ref4$theme,
    gwList = _ref4.gwList,
    restProps = _objectWithoutProperties(_ref4, _excluded);
  var _useState3 = (0, _react.useState)(restProps.rainId),
    _useState4 = _slicedToArray(_useState3, 2),
    rainId = _useState4[0],
    setRainId = _useState4[1];
  var _useState5 = (0, _react.useState)(),
    _useState6 = _slicedToArray(_useState5, 2),
    rainList = _useState6[0],
    setRainList = _useState6[1];
  var rainItem = (0, _react.useMemo)(function () {
    return _lodash["default"].find(rainList, {
      id: rainId
    });
  }, [rainId, rainList]);
  (0, _react.useEffect)(function () {
    if (restProps.rainId) {
      setRainId(restProps.rainId);
    } else {
      var _rainList$;
      setRainId(rainList === null || rainList === void 0 || (_rainList$ = rainList[0]) === null || _rainList$ === void 0 ? void 0 : _rainList$.id);
    }
  }, [restProps.rainId, rainList]);
  return /*#__PURE__*/_react["default"].createElement(_MyModal["default"], {
    title: /*#__PURE__*/_react["default"].createElement(_vtxModal["default"].Title, {
      text: "\u5165\u6D41\u5165\u6E17\u5206\u6790",
      subtitle: "\u8BE6\u60C5"
    }),
    width: 1366,
    footer: theme === 'light' ? /*#__PURE__*/_react["default"].createElement(_button["default"], {
      onClick: onCancel
    }, "\u5173\u95ED") : null,
    visible: visible,
    onCancel: onCancel,
    theme: theme,
    isAntd: true
  }, /*#__PURE__*/_react["default"].createElement(_DeviceDetail["default"], {
    id: id
  }), /*#__PURE__*/_react["default"].createElement(Analysis, {
    setRainList: setRainList,
    rainId: rainId,
    setRainId: setRainId,
    rainItem: rainItem,
    theme: theme,
    gwList: gwList,
    deviceId: id
  }));
};
DeviceModal.propTypes = {
  visible: _propTypes["default"].bool,
  gwList: _propTypes["default"].array,
  onCancel: _propTypes["default"].func,
  id: _propTypes["default"].string,
  theme: _propTypes["default"].string
};
var _default = exports["default"] = DeviceModal;
//# sourceMappingURL=DeviceModal.js.map
