"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 _MyIcon = _interopRequireDefault(require("../_component/MyIcon"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _FormItem = require("../_component/FormItem");
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _featureDraw = _interopRequireDefault(require("@vtx/ol-map/lib/feature-draw"));
var _Modal = _interopRequireDefault(require("../_component/Modal"));
var _RequiredLabel = _interopRequireDefault(require("../_component/RequiredLabel"));
var _service = _interopRequireDefault(require("../_mapUtil/service"));
var _style = require("ol/style");
var _style2 = require("../_mapUtil/style");
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 _startPointFeature$va3, _startPointFeature$va4, _endPointFeature$valu3, _endPointFeature$valu4;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    setVisible = _useProps.setVisible,
    setLoading = _useProps.setLoading,
    setTableData = _useProps.setTableData,
    onClose = _useProps.onClose,
    analysisLayer = _useProps.analysisLayer,
    options = _useProps.options,
    setActiveKey = _useProps.setActiveKey;
  var endPointFeatureRef = (0, _react.useRef)();
  var _useState = (0, _react.useState)(null),
    _useState2 = _slicedToArray(_useState, 2),
    startPointFeature = _useState2[0],
    setStartPointFeature = _useState2[1];
  var _useState3 = (0, _react.useState)(null),
    _useState4 = _slicedToArray(_useState3, 2),
    endPointFeature = _useState4[0],
    setEndPointFeature = _useState4[1];
  var _useState5 = (0, _react.useState)('Point'),
    _useState6 = _slicedToArray(_useState5, 2),
    drawTypeStart = _useState6[0],
    setDrawTypeStart = _useState6[1];
  var _useState7 = (0, _react.useState)(''),
    _useState8 = _slicedToArray(_useState7, 2),
    drawTypeEnd = _useState8[0],
    setDrawTypeEnd = _useState8[1];
  var classnames = function classnames(name) {
    if (name) {
      return "ol-map-analysis-shortestPath-analysis-".concat(name);
    }
    return "ol-map-analysis-shortestPath-analysis";
  };
  var onClosefn = function onClosefn() {
    onClose && onClose();
  };
  // 选择起终点
  var getSelect = function getSelect(type) {
    if (type === 'startPoint') {
      setDrawTypeStart('Point');
      setDrawTypeEnd(null);
      setStartPointFeature(null);
    } else {
      setDrawTypeEnd('Point');
      setEndPointFeature(null);
      setDrawTypeStart(null);
    }
    map.showTip("\u8BF7\u9009\u62E9\u4E00\u4E2A".concat(type === 'startPoint' ? '起点' : '终点'));
  };

  // 计算
  var handleView = function handleView() {
    var _startPointFeature$va, _startPointFeature$va2, _endPointFeature$valu, _endPointFeature$valu2;
    var startPoint = (startPointFeature === null || startPointFeature === void 0 || (_startPointFeature$va = startPointFeature.values_) === null || _startPointFeature$va === void 0 ? void 0 : _startPointFeature$va.code) || (startPointFeature === null || startPointFeature === void 0 || (_startPointFeature$va2 = startPointFeature.values_) === null || _startPointFeature$va2 === void 0 ? void 0 : _startPointFeature$va2.CODE);
    var endPoint = (endPointFeature === null || endPointFeature === void 0 || (_endPointFeature$valu = endPointFeature.values_) === null || _endPointFeature$valu === void 0 ? void 0 : _endPointFeature$valu.code) || (endPointFeature === null || endPointFeature === void 0 || (_endPointFeature$valu2 = endPointFeature.values_) === null || _endPointFeature$valu2 === void 0 ? void 0 : _endPointFeature$valu2.CODE);
    if (startPoint && endPoint) {
      if (startPoint === endPoint) {
        return _message["default"].info('请选择不同的管点', 2);
      } else {
        if ((startPointFeature === null || startPointFeature === void 0 ? void 0 : startPointFeature.key) !== (endPointFeature === null || endPointFeature === void 0 ? void 0 : endPointFeature.key)) {
          return _message["default"].info('请选择相同类型的管点分析！', 2);
        }
        var activeKey = _service["default"].getActiveKeyfromPointToLine(options, startPointFeature === null || startPointFeature === void 0 ? void 0 : startPointFeature.key);
        var params = {
          lineType: _service["default"].getLineType(options, activeKey),
          pointStartCode: startPoint,
          pointEndCode: endPoint
        };
        setActiveKey(activeKey);
        setVisible(true);
        setTableData([]);
        setLoading(true);
        analysisLayer === null || analysisLayer === void 0 || analysisLayer.getData({
          params: params,
          first: true,
          callback: function callback(res) {
            if (res) {
              setTableData(res);
            }
            setLoading(false);
          }
        });
      }
    } else {
      return _message["default"].info('请选择起终点', 2);
    }
  };
  // 起点
  var onDrawStart = function onDrawStart(feature, endPointFeature) {
    _service["default"].getFeature(feature, map, '管点').then(function (feature) {
      // 有起点 并且没有终点
      if (feature && !endPointFeatureRef.current) {
        getSelect('endPoint');
      }
      setStartPointFeature(feature);
    });
  };
  // 终点
  var onDrawEnd = function onDrawEnd(feature) {
    _service["default"].getFeature(feature, map, '管点').then(function (feature) {
      setEndPointFeature(feature);
      endPointFeatureRef.current = feature;
    });
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
    title: "\u6700\u77ED\u8DEF\u5F84\u5206\u6790",
    onClose: onClosefn,
    width: 500
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames()
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('row')
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_RequiredLabel["default"], {
    label: "\u8D77\u70B9",
    type: "field"
  }), (0, _FormItem.useRenderInput)({
    itemProps: {
      placeholder: '请选择起点',
      value: (startPointFeature === null || startPointFeature === void 0 || (_startPointFeature$va3 = startPointFeature.values_) === null || _startPointFeature$va3 === void 0 ? void 0 : _startPointFeature$va3.code) || (startPointFeature === null || startPointFeature === void 0 || (_startPointFeature$va4 = startPointFeature.values_) === null || _startPointFeature$va4 === void 0 ? void 0 : _startPointFeature$va4.CODE),
      addonAfter: /*#__PURE__*/_react["default"].createElement(_MyIcon["default"], {
        type: "icon-public-zuobiaoshiqu",
        onClick: function onClick() {
          return getSelect('startPoint');
        },
        className: "dotIcon"
      })
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: 12
    }
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_RequiredLabel["default"], {
    label: "\u7EC8\u70B9",
    type: "field"
  }), (0, _FormItem.useRenderInput)({
    itemProps: {
      placeholder: '请选择终点',
      value: (endPointFeature === null || endPointFeature === void 0 || (_endPointFeature$valu3 = endPointFeature.values_) === null || _endPointFeature$valu3 === void 0 ? void 0 : _endPointFeature$valu3.code) || (endPointFeature === null || endPointFeature === void 0 || (_endPointFeature$valu4 = endPointFeature.values_) === null || _endPointFeature$valu4 === void 0 ? void 0 : _endPointFeature$valu4.CODE),
      addonAfter: /*#__PURE__*/_react["default"].createElement(_MyIcon["default"], {
        type: "icon-public-zuobiaoshiqu",
        onClick: function onClick() {
          return getSelect('endPoint');
        },
        className: "dotIcon"
      })
    }
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('row')
  }, /*#__PURE__*/_react["default"].createElement(_button["default"], {
    onClick: handleView,
    type: "primary",
    className: "connectBtn"
  }, "\u8BA1\u7B97")))), /*#__PURE__*/_react["default"].createElement(_featureDraw["default"], {
    feature: startPointFeature,
    drawType: drawTypeStart,
    onDrawEnd: onDrawStart,
    style: function style() {
      return [new _style.Style({
        image: new _style.Circle({
          radius: 18,
          fill: new _style.Fill({
            color: '#ff4d4f'
          })
        })
      }), (0, _style2.TextStyle)({
        text: '起点'
      })];
    }
  }), /*#__PURE__*/_react["default"].createElement(_featureDraw["default"], {
    drawType: drawTypeEnd,
    onDrawEnd: onDrawEnd,
    feature: endPointFeature,
    style: function style() {
      return [new _style.Style({
        image: new _style.Circle({
          radius: 18,
          fill: new _style.Fill({
            color: '#ff4d4f'
          })
        })
      }), (0, _style2.TextStyle)({
        text: '终点'
      })];
    }
  }));
};
var _default = exports["default"] = Search;
//# sourceMappingURL=Search.js.map
