"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(e) { return e && e.__esModule ? e : { "default": e }; }
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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
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 */
// eslint-disable-next-line react/prop-types
var DevicePopup = function DevicePopup(_ref) {
  var _facility$dataJson, _facility$dataJson2, _data$result;
  var _ref$info = _ref.info,
    info = _ref$info === void 0 ? {} : _ref$info,
    openModal = _ref.openModal,
    setAnalysisInfo = _ref.setAnalysisInfo,
    showTopologyAnalyse = _ref.showTopologyAnalyse;
  var deviceTypeName = info.deviceTypeName,
    facilityName = info.facilityName,
    code = info.code,
    id = info.id,
    realStatusName = info.realStatusName,
    name = info.name;
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    activeKey = _useState2[0],
    setActiveKey = _useState2[1];
  var _useRequest = (0, _ahooks.useRequest)(function () {
      return (0, _service.fetchQueryData)({
        size: 10000,
        deviceIds: id
      });
    }, {
      refreshDeps: [id]
    }),
    _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 totalOccTimes = gwInfo.totalOccTimes,
    avgDdl = gwInfo.avgDdl,
    facility = gwInfo.facility;
  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: 24
  }].concat(_toConsumableArray((0, _lodash.isEmpty)(data) ? [] : [{
    content: /*#__PURE__*/_react["default"].createElement(_antd.Tabs, {
      size: "small",
      activeKey: activeKey,
      onChange: function onChange(key) {
        return setActiveKey(key);
      },
      style: {
        width: '100%'
      }
    }, data.map(function (item) {
      return /*#__PURE__*/_react["default"].createElement(_antd.Tabs.TabPane, {
        key: item.lineNo,
        tab: item.lineNo
      });
    })),
    span: 24
  }, {
    label: '行政区划',
    value: (facility === null || facility === void 0 ? void 0 : facility.divisionName) || '-',
    span: 12
  }, {
    label: '管长',
    value: (facility === null || facility === void 0 || (_facility$dataJson = facility.dataJson) === null || _facility$dataJson === void 0 ? void 0 : _facility$dataJson.lineLength) + 'm',
    span: 12
  }, {
    label: '管径',
    value: (facility === null || facility === void 0 || (_facility$dataJson2 = facility.dataJson) === null || _facility$dataJson2 === void 0 ? void 0 : _facility$dataJson2.ds) + 'mm',
    span: 12
  }, {
    label: '雨污混接次数',
    value: totalOccTimes,
    span: 12
  }, {
    label: '平均电导率',
    value: /*#__PURE__*/_react["default"].createElement("span", {
      style: {
        color: data !== null && data !== void 0 && (_data$result = data.result) !== null && _data$result !== void 0 && _data$result.config.ddlThreshold ? '#FE0000' : ''
      }
    }, (avgDdl || 0) + 'μS/cm'),
    span: 12
  }]));
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: 'ol-map-analysis-sedimentation-ol-popup'
  }, /*#__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: showTopologyAnalyse ? [{
      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,
    showTopologyAnalyse = _ref2.showTopologyAnalyse;
  var _useGetDeviceList = (0, _useGetDeviceList2["default"])('w_wq_ddl'),
    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,
      showTopologyAnalyse: showTopologyAnalyse
    });
  });
  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
