"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _GwLayer = _interopRequireDefault(require("../_component/GwLayer"));
var _config = require("./config");
var _antd = require("antd");
var _MyTag = _interopRequireDefault(require("../_component/MyTag"));
var _config2 = _interopRequireDefault(require("../_mapUtil/config"));
var _olMap = require("@vtx/ol-map");
var _ahooks = require("ahooks");
var _service = require("./service");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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); }
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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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); }
// eslint-disable-next-line react/prop-types
var Popup = function Popup(_ref) {
  var _info$dataJson, _info$dataJson2, _data$result;
  var _ref$info = _ref.info,
    info = _ref$info === void 0 ? {} : _ref$info,
    openModal = _ref.openModal;
  var totalOccTimes = info.totalOccTimes,
    avgDdl = info.avgDdl,
    facilityClassName = info.facilityClassName,
    sewageMixedType = info.sewageMixedType,
    facilityClassCode = info.facilityClassCode,
    facilityId = info.facilityId;
  var _useRequest = (0, _ahooks.useRequest)(function () {
      if (facilityId) {
        return (0, _service.fetchQueryDataResult)({
          facilityId: facilityId
        });
      }
      return {};
    }, {
      refreshDeps: [facilityId]
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? {} : _useRequest$data;
  var list = [{
    content: /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
      text: _config.RainSewageTypeName[sewageMixedType],
      color: _config.RainSewageTypeColor[sewageMixedType]
    }), /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
      text: facilityClassName,
      color: _config2["default"].gwColorMap[facilityClassCode]
    })),
    span: 24
  }, {
    label: '所在道路',
    value: info.roadName || '-',
    span: 24
  }, {
    label: '管长',
    value: (info === null || info === void 0 || (_info$dataJson = info.dataJson) === null || _info$dataJson === void 0 ? void 0 : _info$dataJson.lineLength) + 'm',
    span: 12
  }, {
    label: '管径',
    value: (info === null || info === void 0 || (_info$dataJson2 = info.dataJson) === null || _info$dataJson2 === void 0 ? void 0 : _info$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(_olMap.Popup.Template, {
    contentList: list,
    column: 2,
    contentStyle: {
      width: 390
    },
    detail: {
      show: true,
      onClick: function onClick() {
        var _info$facility;
        return openModal({
          facilityId: info === null || info === void 0 || (_info$facility = info.facility) === null || _info$facility === void 0 ? void 0 : _info$facility.id
        });
      }
    }
  });
};
var MapLayer = function MapLayer(_ref2) {
  var data = _ref2.data,
    openModal = _ref2.openModal;
  var group = [_config.RainSewageType.ZC, _config.RainSewageType.YWHJ].map(function (key) {
    return {
      name: _config.RainSewageTypeName[key],
      key: "RAIN_SEWAGE_GW_".concat(key),
      color: _config.RainSewageTypeColor[key],
      filter: function filter(f) {
        return f.sewageMixedType === key;
      }
    };
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_GwLayer["default"], {
    lineData: data.map(function (item) {
      return _objectSpread(_objectSpread({}, item), (item === null || item === void 0 ? void 0 : item.facility) || {});
    }),
    pointData: data.map(function (item) {
      var _item$facility, _item$facility2;
      return _objectSpread(_objectSpread(_objectSpread({}, item), (item === null || item === void 0 ? void 0 : item.facility) || {}), {}, {
        geometryInfo: _objectSpread(_objectSpread({}, (item === null || item === void 0 || (_item$facility = item.facility) === null || _item$facility === void 0 ? void 0 : _item$facility.geometryInfo) || {}), {}, {
          lngLats: item === null || item === void 0 || (_item$facility2 = item.facility) === null || _item$facility2 === void 0 || (_item$facility2 = _item$facility2.geometryInfo) === null || _item$facility2 === void 0 || (_item$facility2 = _item$facility2.lngLats) === null || _item$facility2 === void 0 || (_item$facility2 = _item$facility2.split(';')) === null || _item$facility2 === void 0 ? void 0 : _item$facility2[0],
          type: 'point'
        })
      });
    }),
    showDevice: false,
    deviceData: data.filter(function (item) {
      return item.device;
    }).map(function (item) {
      return _objectSpread(_objectSpread({}, item.device), {}, {
        geometryInfo: item.device.installLocationDTO
      });
    }),
    group: group,
    id: 'RAIN_SEWAGE_GW',
    template: function template(feature) {
      return /*#__PURE__*/_react["default"].createElement(Popup, {
        info: feature.values_,
        openModal: openModal
      });
    }
  }));
};
MapLayer.propTypes = {
  data: _propTypes["default"].array,
  openModal: _propTypes["default"].func
};
var _default = exports["default"] = MapLayer;
//# sourceMappingURL=MapLayer.js.map
