"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 _useGetDeviceList2 = _interopRequireDefault(require("../_mapUtil/useGetDeviceList"));
var _ahooks = require("ahooks");
var _antd = require("antd");
var _MyTag = _interopRequireDefault(require("../_component/MyTag"));
var _lodash = require("lodash");
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _service = require("./service");
var _olMap = require("@vtx/ol-map");
var _useModal2 = _interopRequireDefault(require("../_mapUtil/useModal"));
var _DeviceModal = _interopRequireDefault(require("./DeviceModal"));
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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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; } /* eslint-disable react/prop-types */
// eslint-disable-next-line react/prop-types
var DevicePopup = function DevicePopup(_ref) {
  var _ref$info = _ref.info,
    info = _ref$info === void 0 ? {} : _ref$info,
    openModal = _ref.openModal,
    rainId = _ref.rainId,
    setAnalysisInfo = _ref.setAnalysisInfo,
    flowAnalyseShow = _ref.flowAnalyseShow;
  var divisionName = info.divisionName,
    deviceTypeName = info.deviceTypeName,
    facilityName = info.facilityName,
    code = info.code,
    id = info.id,
    realStatusName = info.realStatusName,
    name = info.name,
    monitorItemCodes = info.monitorItemCodes;
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    activeKey = _useState2[0],
    setActiveKey = _useState2[1];
  var _useRequest = (0, _ahooks.useRequest)(function () {
      if (rainId) {
        return (0, _service.fetchQueryData)({
          size: 10000,
          rainId: rainId,
          deviceIds: id
        });
      }
      return [id, rainId];
    }, {
      refreshDeps: [rainId]
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? [] : _useRequest$data;
  (0, _react.useEffect)(function () {
    if (!(0, _lodash.isEmpty)(data)) {
      setActiveKey(data[0].lineNo);
    }
  }, [data]);
  var gwInfo = data.find(function (item) {
    return item.lineNo === activeKey;
  }) || {};
  var rainyAvgWaterLevel = gwInfo.rainyAvgWaterLevel,
    sunnyAvgWaterLevel = gwInfo.sunnyAvgWaterLevel,
    rainyAvgFlow = gwInfo.rainyAvgFlow,
    sunnyAvgFlow = gwInfo.sunnyAvgFlow;
  var list = [{
    span: 24,
    content: /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
      text: deviceTypeName,
      color: _config["default"].colorMap.blue
    }), /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
      text: realStatusName,
      color: _config["default"].colorMap.blue
    }))
  }, {
    label: '设备编码',
    value: code || '-',
    span: 24
  }, {
    label: '所属设施',
    value: facilityName || '-',
    span: 12
  }, {
    label: '行政区划',
    value: divisionName || '-',
    span: 12
  }].concat(_toConsumableArray((0, _lodash.isEmpty)(data) ? [] : [{
    content: /*#__PURE__*/_react["default"].createElement(_antd.Tabs, {
      size: "small",
      activeKey: activeKey,
      onChange: function onChange(key) {
        return setActiveKey(key);
      }
    }, data.map(function (item) {
      return /*#__PURE__*/_react["default"].createElement(_antd.Tabs.TabPane, {
        key: item.lineNo,
        tab: item.lineNo
      });
    })),
    span: 24
  }, {
    label: '晴天平均液位',
    value: (sunnyAvgWaterLevel || 0) + 'm'
  }, {
    label: '晴天平均流量',
    value: (sunnyAvgFlow || 0) + 'm³/h'
  }, {
    label: '雨天平均液位',
    value: (rainyAvgWaterLevel || 0) + 'm'
  }, {
    label: '雨天平均流量',
    value: (rainyAvgFlow || 0) + 'm³/h'
  }]));
  return /*#__PURE__*/_react["default"].createElement(_olMap.Popup.Template, {
    contentList: list,
    column: 2,
    contentStyle: {
      width: 390
    },
    detail: {
      show: true,
      onClick: function onClick() {
        return openModal({
          id: info.id,
          gwList: data
        });
      }
    },
    footerList: monitorItemCodes.includes('w_flow_now') && flowAnalyseShow ? [{
      icon: /*#__PURE__*/_react["default"].createElement("img", {
        src: require('./assets/analysis.png'),
        width: 20,
        height: 20,
        style: {
          marginBottom: 4
        }
      }),
      label: '流量分析',
      onClick: function onClick() {
        setAnalysisInfo({
          show: true,
          deviceId: id,
          deviceName: name
        });
      }
    }] : []
  });
};
var DeviceLayer = function DeviceLayer(_ref2) {
  var rainId = _ref2.rainId,
    setAnalysisInfo = _ref2.setAnalysisInfo,
    flowAnalyseShow = _ref2.flowAnalyseShow;
  var _useGetDeviceList = (0, _useGetDeviceList2["default"])('w_liquid_level,w_flow_now'),
    deviceList = _useGetDeviceList.data,
    deviceGroup = _useGetDeviceList.deviceGroup;
  var _useModal = (0, _useModal2["default"])(),
    modalInfo = _useModal.modalInfo,
    onOpenModal = _useModal.onOpenModal,
    onCancel = _useModal.onCancel;
  var deviceTemplate = (0, _ahooks.useMemoizedFn)(function (feature) {
    return /*#__PURE__*/_react["default"].createElement(DevicePopup, {
      info: feature.values_,
      openModal: onOpenModal,
      rainId: rainId,
      setAnalysisInfo: setAnalysisInfo,
      flowAnalyseShow: flowAnalyseShow
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: deviceList,
    name: "\u8BBE\u5907",
    id: "DEVICE",
    group: deviceGroup,
    template: deviceTemplate,
    labelField: "name",
    cluster: true,
    zIndex: 61
  }), modalInfo.visible && /*#__PURE__*/_react["default"].createElement(_DeviceModal["default"], _extends({}, modalInfo.info, {
    onCancel: onCancel,
    visible: modalInfo.visible,
    rainId: rainId
  })));
};
var _default = exports["default"] = DeviceLayer;
//# sourceMappingURL=DeviceLayer.js.map
