"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 _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _featureDraw = _interopRequireDefault(require("@vtx/ol-map/lib/feature-draw"));
var _GetData = _interopRequireDefault(require("../_mapUtil/GetData"));
var _ToolsSelect = _interopRequireDefault(require("../_component/ToolsSelect"));
var _Select = _interopRequireDefault(require("../_component/Select"));
var _Input = _interopRequireDefault(require("../_component/Input"));
var _Modal = _interopRequireDefault(require("../_component/Modal"));
var _service = _interopRequireDefault(require("../_mapUtil/service"));
var _lodash = _interopRequireDefault(require("lodash"));
var _Observable = require("ol/Observable");
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 _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; } /**
 * 条件相关
 * @description: 用于展示条件查询、绘制控件等
 */
var Search = function Search() {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    highLayer = _useProps.highLayer,
    setVisible = _useProps.setVisible,
    setLoading = _useProps.setLoading,
    setTableData = _useProps.setTableData,
    options = _useProps.options,
    activeKey = _useProps.activeKey,
    onClose = _useProps.onClose;
  var _useState = (0, _react.useState)('DragBox'),
    _useState2 = _slicedToArray(_useState, 2),
    activeBtn = _useState2[0],
    setActiveBtn = _useState2[1]; // 框选选择
  var _useState3 = (0, _react.useState)(),
    _useState4 = _slicedToArray(_useState3, 2),
    layerKeys = _useState4[0],
    setLayerKeys = _useState4[1]; // 选中图层keys
  var _useState5 = (0, _react.useState)(''),
    _useState6 = _slicedToArray(_useState5, 2),
    drawType = _useState6[0],
    setDrawType = _useState6[1];
  var _useState7 = (0, _react.useState)(null),
    _useState8 = _slicedToArray(_useState7, 2),
    feature = _useState8[0],
    setFeature = _useState8[1]; // 框选绘制feature
  var _useState9 = (0, _react.useState)(''),
    _useState10 = _slicedToArray(_useState9, 2),
    ageField = _useState10[0],
    setAgeField = _useState10[1]; // 使用寿命
  var _useState11 = (0, _react.useState)([]),
    _useState12 = _slicedToArray(_useState11, 2),
    flatCoordinates = _useState12[0],
    setFlatCoordinates = _useState12[1];
  var _useState13 = (0, _react.useState)([]),
    _useState14 = _slicedToArray(_useState13, 2),
    dataSource = _useState14[0],
    setDataSource = _useState14[1];
  var moveKey = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    setLayerKeys(options);
  }, [options]);
  (0, _react.useEffect)(function () {
    _service["default"].getSimpleList({
      options: options,
      tableData: dataSource.filter(function (item) {
        return item.key == activeKey;
      }),
      activeKey: activeKey
    }).then(function (_ref) {
      var dataSource = _ref.dataSource;
      setTableData(dataSource);
    });
  }, [dataSource, activeKey]);
  (0, _react.useEffect)(function () {
    setDrawType('');
    if (activeBtn && activeBtn !== 'CurrentView') {
      setDrawType(activeBtn);
    }
  }, [activeBtn]);
  var onToolsChange = function onToolsChange(key) {
    setTableData([]);
    setActiveBtn(key);
    highLayer === null || highLayer === void 0 || highLayer.clearFeatures();
    moveKey.current && (0, _Observable.unByKey)(moveKey.current);
    if (key && key !== 'CurrentView') {} else if (key === 'CurrentView') {
      setFeature(null);
      setFlatCoordinates(_service["default"].getExtend(map));
    }
  };
  var onClosefn = function onClosefn() {
    onClose && onClose();
    setTableData([]);
  };
  var onDrawEnd = function onDrawEnd(feature, _distance) {
    setFeature(_lodash["default"].cloneDeep(feature));
  };
  (0, _react.useEffect)(function () {
    getData();
  }, [feature, ageField, flatCoordinates, layerKeys]);
  /**
   * @description: 图层高亮
   * @param {*} features
   * @return {*}
   */
  var highLayerFn = function highLayerFn(features) {
    if (activeBtn !== 'CurrentView') highLayer === null || highLayer === void 0 || highLayer.setHighlight(features);
  };
  var getData = function getData() {
    if (feature || flatCoordinates !== null && flatCoordinates !== void 0 && flatCoordinates.length) {
      setVisible(true);
      setLoading(true);
      setTableData([]);
      (0, _GetData["default"])({
        feature: feature,
        map: map,
        highLayerFn: highLayerFn,
        flatCoordinates: flatCoordinates,
        drawType: activeBtn,
        key: layerKeys,
        filterBefore: function filterBefore(filter) {
          var _filter = '';
          var cqFilter = "buildDate = ".concat(ageField);
          if (filter) {
            _filter = ageField ? "".concat(cqFilter, " and ").concat(filter) : filter;
          } else {
            _filter = ageField ? cqFilter : '';
          }
          return _filter;
        }
      }).then(function (res) {
        var _res$data;
        setLoading(false);
        if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.length) {
          setDataSource(res === null || res === void 0 ? void 0 : res.data);
        }
      });
    }
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
    title: "\u5E74\u9650\u9884\u8B66",
    onClose: onClosefn,
    width: 500
  }, /*#__PURE__*/_react["default"].createElement(_ToolsSelect["default"], {
    title: "",
    value: activeBtn,
    onChange: onToolsChange,
    options: _service["default"].btnList || []
  }), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
    mode: "multiple",
    options: _service["default"].getLayerOption(map, map.layers.getShowKeys()) || [],
    title: "\u67E5\u8BE2\u56FE\u5C42",
    onChange: function onChange(e) {
      setLayerKeys(e);
    },
    value: layerKeys,
    width: 300,
    layout: "horizontal"
  }), /*#__PURE__*/_react["default"].createElement(_Input["default"], {
    type: "number",
    title: "\u4F7F\u7528\u5BFF\u547D(\u5E74)",
    onChange: function onChange(e) {
      setAgeField(e);
    },
    width: 276,
    layout: "horizontal"
  }), /*#__PURE__*/_react["default"].createElement(_featureDraw["default"], {
    drawType: drawType,
    onDrawEnd: onDrawEnd
  })));
};
var _default = exports["default"] = Search;
//# sourceMappingURL=Search.js.map
