"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 _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _olMap = require("@vtx/ol-map");
var _lodash = require("lodash");
var _Status = _interopRequireDefault(require("./Status"));
var _config = _interopRequireDefault(require("../config"));
var turf = _interopRequireWildcard(require("@turf/turf"));
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var getMapCenter = function getMapCenter(lngLats) {
  var _center;
  var center = [];
  var list = lngLats.split(';').map(function (v) {
    var newLng = v.split(',');
    return [Number(newLng[0]), Number(newLng[1])];
  });
  var polygon = turf.polygon([list], {
    name: 'poly1'
  });
  center = turf.centroid(polygon);
  return (_center = center) === null || _center === void 0 || (_center = _center.geometry) === null || _center === void 0 ? void 0 : _center.coordinates;
};

// eslint-disable-next-line react/prop-types
var Popup = function Popup(_ref) {
  var _ref$info = _ref.info,
    info = _ref$info === void 0 ? {} : _ref$info,
    openModal = _ref.openModal,
    _ref$searchParams = _ref.searchParams,
    searchParams = _ref$searchParams === void 0 ? {} : _ref$searchParams;
  var divisionNames = info.divisionNames,
    balanceRate = info.balanceRate,
    supplyWater = info.supplyWater,
    drainageWater = info.drainageWater;
  var list = [{
    span: 24,
    content: /*#__PURE__*/_react["default"].createElement(_Status["default"], {
      info: info
    })
  }, {
    label: '行政区划',
    value: divisionNames || '-',
    span: 12
  }, {
    label: '水平衡系数',
    value: "".concat(balanceRate || 0),
    span: 12
  }, {
    label: '供水量',
    value: "".concat(supplyWater || 0, "m\xB3"),
    span: 12
  }, {
    label: '排水量',
    value: "".concat(drainageWater || 0, "m\xB3"),
    span: 12
  }, {
    label: '监测日期',
    value: "".concat(searchParams.startDate, "\u81F3").concat(searchParams.endDate),
    span: 24
  }

  // {
  //     label: '充溢度',
  //     content: (
  //         <Space>
  //             <Progress
  //                 percent={degree}
  //                 strokeColor={color}
  //                 showInfo={false}
  //                 style={{ width: 270 }}
  //             />
  //             <span style={{ color: color }}>{degree}%</span>
  //         </Space>
  //     ),
  // },
  ];
  return /*#__PURE__*/_react["default"].createElement(_olMap.Popup.Template, {
    contentList: list,
    column: 2,
    contentStyle: {
      width: 390
    },
    detail: {
      show: true,
      onClick: function onClick() {
        return openModal(info);
      }
    }
  });
};
var MapLayer = function MapLayer(_ref2) {
  var data = _ref2.data,
    openModal = _ref2.openModal,
    _ref2$searchParams = _ref2.searchParams,
    searchParams = _ref2$searchParams === void 0 ? {} : _ref2$searchParams;
  var group = (0, _react.useMemo)(function () {
    return _config["default"].districtLevelList.map(function (item) {
      return {
        name: "".concat(item.value, "\u7247\u533A"),
        key: "WATER_BALANCE_ANALYSIS_DISTRICT_".concat(item.key),
        color: '#1677FF',
        background: 'rgb(22,119,255)',
        dataSource: data.filter(function (v) {
          return String(v.districtLevel) === String(item.key);
        })
      };
    });
  }, [data]);
  var _useProps = (0, _olMap.useProps)(),
    map = _useProps.map;
  (0, _react.useEffect)(function () {
    if (!(0, _lodash.isEmpty)(group)) {
      map.layers.onChange();
    }
  }, [group]);
  return !(0, _lodash.isEmpty)(group) && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, group.filter(function (v) {
    return v.dataSource.length > 0;
  }).map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
      key: item.key
      // name={item.name}
      ,
      id: item.key,
      data: item.dataSource,
      labelField: "districtName",
      zIndex: 5,
      style: {
        type: 'Polygon',
        style: {
          stroke: {
            color: item.color,
            opacity: 1,
            width: 2
          },
          fill: {
            color: item.color,
            opacity: 0.6
          }
        }
      },
      template: function template(feature) {
        return /*#__PURE__*/_react["default"].createElement(Popup, {
          info: feature.values_,
          openModal: openModal,
          searchParams: searchParams
        });
      }
    });
  }), data.length > 0 && data.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_olMap.Dom, {
      key: item.facilityId,
      data: getMapCenter(item.geometryInfo.lngLats),
      stopEvent: false
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "water-balance-ball"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "water-balance-ball-title"
    }, item.districtName), /*#__PURE__*/_react["default"].createElement("span", {
      className: "water-balance-ball-count",
      style: {
        color: item.colorVal
      }
    }, item.balanceRate)));
  }));
};
MapLayer.propTypes = {
  data: _propTypes["default"].array,
  rules: _propTypes["default"].object,
  openModal: _propTypes["default"].func,
  searchParams: _propTypes["default"].object
};
var _default = exports["default"] = MapLayer;
//# sourceMappingURL=MapLayer.js.map
