"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 _GwLayer = _interopRequireDefault(require("../_component/GwLayer"));
var _olMap = require("@vtx/ol-map");
var _lodash = require("lodash");
var _antd = require("antd");
var _Status = _interopRequireDefault(require("./Status"));
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 }; }
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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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); }
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; }
var getExpressionStr = function getExpressionStr(expression, op) {
  var opObj = {
    /**
     * 等于
     */
    EQ: 'EQ',
    /**
     * 大于
     */
    GT: 'GT',
    /**
     * 大于等于
     */
    GE: 'GE',
    /**
     * 小于
     */
    LT: 'LT',
    /**
     * 小于等于
     */
    LE: 'LE',
    /**
     * 介于
     */
    BETWEEN: 'BETWEEN'
  };
  if (op === opObj.EQ) {
    return "[".concat(expression, "%, ").concat(expression, "%]");
  } else if ([opObj.LT, opObj.LE].includes(op)) {
    return "(0%, ".concat(expression, "%").concat(op === opObj.LE ? ']' : ')');
  } else if ([opObj.GT, opObj.GE].includes(op)) {
    return "".concat(op === opObj.GE ? '[' : '(').concat(expression, "%, 100%]");
  } else if (op === opObj.BETWEEN) {
    var _expression$split = expression.split(','),
      _expression$split2 = _slicedToArray(_expression$split, 2),
      left = _expression$split2[0],
      right = _expression$split2[1];
    return "[".concat(left, "%, ").concat(right, "%]");
  }
  return '';
};

// eslint-disable-next-line react/prop-types
var Popup = function Popup(_ref) {
  var _rules$level;
  var _ref$info = _ref.info,
    info = _ref$info === void 0 ? {} : _ref$info,
    openModal = _ref.openModal,
    _ref$rules = _ref.rules,
    rules = _ref$rules === void 0 ? {} : _ref$rules;
  var roadName = info.roadName,
    waterLevel = info.waterLevel,
    diameter = info.diameter,
    degree = info.degree,
    level = info.level;
  var color = (_rules$level = rules[level]) === null || _rules$level === void 0 ? void 0 : _rules$level.color;
  var list = [{
    span: 24,
    content: /*#__PURE__*/_react["default"].createElement(_Status["default"], {
      info: info,
      rules: rules
    })
  }, {
    label: '所在道路',
    value: roadName || '-',
    span: 24
  }, {
    label: '液位',
    value: "".concat(waterLevel || 0, "m"),
    span: 12
  }, {
    label: '管径',
    value: "".concat(diameter || 0, "mm"),
    span: 12
  }, {
    label: '充溢度',
    content: /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement(_antd.Progress, {
      percent: degree,
      strokeColor: color,
      showInfo: false,
      style: {
        width: 270
      }
    }), /*#__PURE__*/_react["default"].createElement("span", {
      style: {
        color: color
      }
    }, degree, "%"))
  }];
  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$rules = _ref2.rules,
    rules = _ref2$rules === void 0 ? [] : _ref2$rules;
  var group = Object.values(rules).map(function (_ref3) {
    var name = _ref3.name,
      level = _ref3.level,
      color = _ref3.color,
      expression = _ref3.expression,
      op = _ref3.op;
    return {
      name: "".concat(name).concat(getExpressionStr(expression, op)),
      key: "FILLING_DEGREE_ANALYSIS_GW_".concat(level),
      color: color,
      filter: function filter(f) {
        return String(f.level) === String(level);
      }
    };
  });
  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, /*#__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'
        })
      });
    }),
    group: group,
    id: 'FILLING_DEGREE_ANALYSIS_GW',
    template: function template(feature) {
      return /*#__PURE__*/_react["default"].createElement(Popup, {
        info: feature.values_,
        openModal: openModal,
        rules: rules
      });
    }
  }));
};
MapLayer.propTypes = {
  data: _propTypes["default"].array,
  rules: _propTypes["default"].object,
  openModal: _propTypes["default"].func
};
var _default = exports["default"] = MapLayer;
//# sourceMappingURL=MapLayer.js.map
