"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 _button = _interopRequireDefault(require("antd/lib/button"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _select = _interopRequireDefault(require("antd/lib/select"));
var _Modal = _interopRequireDefault(require("../_component/Modal"));
var _request = _interopRequireDefault(require("../_mapUtil/request"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
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 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 _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; } /**
 * @returns 纵断面分析(供水、污水)
 */
function Search(props) {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    analysisLayer = _useProps.analysisLayer,
    profileModal = _useProps.profileModal,
    setProfileModal = _useProps.setProfileModal,
    selectLayer = _useProps.selectLayer,
    setVisible = _useProps.setVisible,
    _useProps$selectList = _useProps.selectList,
    selectList = _useProps$selectList === void 0 ? [] : _useProps$selectList,
    setSelectList = _useProps.setSelectList,
    onClose = _useProps.onClose;
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    codeOptions = _useState2[0],
    setCodeOptions = _useState2[1];
  var _useState3 = (0, _react.useState)([]),
    _useState4 = _slicedToArray(_useState3, 2),
    codeList = _useState4[0],
    setCodeList = _useState4[1];
  var hide = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    var newCodeList = analysisLayer === null || analysisLayer === void 0 ? void 0 : analysisLayer.getCodeList(selectList);
    var newCodeOptions = getSelectOptions(selectList);
    setCodeList(newCodeList);
    setCodeOptions(newCodeOptions);
  }, [selectList]);
  var handleClose = function handleClose() {
    setSelectList([]);
    setVisible(false);
    onClose && onClose();
  };

  // 获取下拉选数据
  var getSelectOptions = function getSelectOptions(list) {
    var options = [];
    if (list && list.length) {
      list.map(function (item) {
        var _item$values_;
        var code = item === null || item === void 0 || (_item$values_ = item.values_) === null || _item$values_ === void 0 ? void 0 : _item$values_.code;
        var key = item === null || item === void 0 ? void 0 : item.key;
        if (code) {
          options.push({
            label: code,
            value: code,
            key: key
          });
        }
      });
    }
    return options;
  };
  var handleCodes = function handleCodes(list) {
    var newList = [];
    list && list.length && list.map(function (item) {
      newList.push.apply(newList, _toConsumableArray(item.split('_')));
    });
    return newList;
  };

  // 查看
  var handleView = function handleView() {
    var _selectList$;
    setVisible(true);
    if (!(selectList !== null && selectList !== void 0 && selectList.length)) {
      _message["default"].warning('请先选择管线！');
      return;
    }
    var codes = analysisLayer === null || analysisLayer === void 0 ? void 0 : analysisLayer.getCodeList(selectList);
    var flagList = [];
    if (codes && codes.length > 1) {
      codes.map(function (item, index) {
        flagList[index] = '0';
        var _list = codes.filter(function (val) {
          return val !== item;
        });
        var list = handleCodes(_list);
        var _item = item.split('_');
        _item && _item.length && _item.map(function (v) {
          if (list.includes(v)) {
            flagList[index] = '1'; // 连续
          }
        });
      });
      if (flagList.includes('0')) {
        return _message["default"].info('请选择连续的管线进行分析！', 2);
      }
    }
    var params = {
      codes: codes,
      // 排水类型是1供水类型是2
      lineType: selectList !== null && selectList !== void 0 && (_selectList$ = selectList[0]) !== null && _selectList$ !== void 0 && (_selectList$ = _selectList$.key) !== null && _selectList$ !== void 0 && _selectList$.toUpperCase().includes('SUPPLY') ? '2' : '1'
    };
    hide.current = _message["default"].loading('分析中', 0);
    _request["default"].post("".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/longitudinalSectionAnalyse"), {
      body: params
    }).then(function (res) {
      hide.current();
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0') {
        var _res$data;
        if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.length) {
          profileModal.modalShow = true;
          profileModal.modalData = res.data;
          setProfileModal(_objectSpread({}, profileModal));
        }
      }
    });
  };
  // 清除选中管网
  var onDeselect = function onDeselect(val) {
    var list = [];
    var feature = selectList.find(function (item) {
      var _item$values_2;
      return (item === null || item === void 0 || (_item$values_2 = item.values_) === null || _item$values_2 === void 0 ? void 0 : _item$values_2.code) === val;
    });
    selectLayer.getSource().removeFeature(feature);
    var index = selectList.findIndex(function (item) {
      var _item$values_3;
      return (item === null || item === void 0 || (_item$values_3 = item.values_) === null || _item$values_3 === void 0 ? void 0 : _item$values_3.code) === val;
    });
    selectList.splice(index, 1);
    list = list.concat(selectList);
    map.selectList = list;
    setSelectList(list);
  };
  var classnames = function classnames(name) {
    if (name) {
      return "ol-map-analysis-profileanalysis-".concat(name);
    }
    return "ol-map-analysis-profileanalysis";
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
    title: "\u7EB5\u622A\u9762\u5206\u6790",
    onClose: handleClose
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('formWrap')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      position: 'relative',
      marginBottom: 12
    }
  }, /*#__PURE__*/_react["default"].createElement("label", null, "\u7BA1\u9053\u7F16\u53F7:"), /*#__PURE__*/_react["default"].createElement(_select["default"], {
    style: {
      width: 200
    },
    mode: "multiple",
    options: codeOptions,
    value: codeList,
    showSearch: false,
    allowClear: false,
    dropdownStyle: {
      display: 'none'
    },
    onDeselect: onDeselect
  }), /*#__PURE__*/_react["default"].createElement(_button["default"], {
    onClick: handleView,
    type: "primary"
  }, "\u5206\u6790")))));
}
var _default = exports["default"] = Search;
//# sourceMappingURL=Search.js.map
