"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.Toolbox = void 0;
exports["default"] = Tool;
var _react = _interopRequireWildcard(require("react"));
var _ItemWrap = _interopRequireDefault(require("../components/ItemWrap"));
var _ToolItem = _interopRequireDefault(require("../components/ToolItem"));
var _Icon = _interopRequireDefault(require("../components/Icon"));
var _Distance = _interopRequireDefault(require("./Measure/Distance"));
var _Area = _interopRequireDefault(require("./Measure/Area"));
var _MapPrint = _interopRequireDefault(require("./MapPrint"));
var _MapDownload = _interopRequireDefault(require("./MapDownload"));
var _EagleEye = _interopRequireDefault(require("./EagleEye"));
var _ScaleLine = _interopRequireDefault(require("./ScaleLine"));
var _MapBookmark = _interopRequireDefault(require("./MapBookmark"));
var _useProps2 = _interopRequireDefault(require("../../use-props"));
var _BoxSelect = _interopRequireDefault(require("./BoxSelect"));
var _CircleSelect = _interopRequireDefault(require("./CircleSelect"));
var _PolygonSelect = _interopRequireDefault(require("./PolygonSelect"));
var _SpaceQuery = _interopRequireDefault(require("./SpaceQuery"));
var _draftingPrint = _interopRequireDefault(require("./draftingPrint"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var P = {
  measureDistance: _Distance["default"],
  measureArea: _Area["default"],
  mapPrint: _MapPrint["default"],
  mapDownload: _MapDownload["default"],
  mapBookmark: _MapBookmark["default"],
  boxSelect: _BoxSelect["default"],
  circleSelect: _CircleSelect["default"],
  polygonSelect: _PolygonSelect["default"],
  spaceQuery: _SpaceQuery["default"],
  draftingPrint: _draftingPrint["default"]
};
var Toolbox = exports.Toolbox = function Toolbox(props) {
  var type = props.type;
  var Page = P[type];
  return /*#__PURE__*/_react["default"].createElement(Page, props);
};
function Tool(props) {
  var onScaleLineClick = props.onScaleLineClick,
    onEagleEyeClick = props.onEagleEyeClick,
    active = props.active,
    setActive = props.setActive;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    TextEnum = _useProps.TextEnum;
  var itemWrapRef = (0, _react.useRef)();
  var options = [{
    label: TextEnum.toolMeasureDistanceText,
    icon: 'icon-ceju',
    key: 'measureDistance'
  }, {
    label: TextEnum.toolMeasureAreaText,
    icon: 'icon-mianji',
    key: 'measureArea'
  }, {
    label: TextEnum.toolMapBookmark,
    icon: 'icon-shuqian',
    key: 'mapBookmark'
  }, {
    label: TextEnum.toolMapDownload,
    icon: 'icon-dituxiazai',
    key: 'mapDownload'
  }, {
    label: TextEnum.toolMapPrint,
    icon: 'icon-ditudayin',
    key: 'mapPrint'
  }, {
    label: TextEnum.toolDraftingPrint,
    icon: 'icon-ditudayin',
    key: 'draftingPrint'
  }];
  (0, _react.useEffect)(function () {
    // 挂载关闭工具方法
    map.closeToolbox = function () {
      setActive('');
    };
    return function () {
      // 移除关闭工具方法
      delete map.closeToolbox;
    };
  }, []);
  var onChange = function onChange(v) {
    if (!v.key || v.key === 'pointSelect') {
      return;
    }

    // 关闭气泡
    itemWrapRef.current.setVisible(false);
    var value = active && v.key === active ? '' : v.key;

    // 执行关闭分析
    map.closeAnalysis && map.closeAnalysis();

    // 增加当前激活的工具属性
    map.toolboxActive = value;
    setActive(value);
  };
  return /*#__PURE__*/_react["default"].createElement(_ItemWrap["default"], {
    ref: itemWrapRef,
    content: /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
      type: "icon-gongju"
    })
  }, options && options.length > 0 && options.map(function (v) {
    var params = props[v.key];
    // console.log(111111, v.key, params);
    if (params !== null && params !== void 0 && params.show) {
      return /*#__PURE__*/_react["default"].createElement(_ToolItem["default"], {
        key: v.label,
        onClick: function onClick() {
          return onChange(v);
        },
        label: v.label,
        icon: v.icon,
        active: active === v.key || v.active
      });
    } else {
      return null;
    }
  }), /*#__PURE__*/_react["default"].createElement(_ScaleLine["default"], {
    onClick: function onClick(val) {
      itemWrapRef.current.setVisible(false);
      onScaleLineClick === null || onScaleLineClick === void 0 || onScaleLineClick(val);
    }
  }), /*#__PURE__*/_react["default"].createElement(_EagleEye["default"], {
    onClick: function onClick(val) {
      itemWrapRef.current.setVisible(false);
      onEagleEyeClick === null || onEagleEyeClick === void 0 || onEagleEyeClick(val);
    }
  }));
}
Tool.defaultProps = {
  measureDistance: {
    show: true
  },
  measureArea: {
    show: true
  },
  pointSelect: {
    show: true
  },
  boxSelect: {
    show: true
  },
  circleSelect: {
    show: true
  },
  polygonSelect: {
    show: true
  },
  mapBookmark: {
    show: true
  },
  mapDownload: {
    show: true
  },
  mapPrint: {
    show: true
  },
  eagleEye: {
    show: true
  },
  scaleLine: {
    show: true
  },
  spaceQuery: {
    show: true
  },
  draftingPrint: {
    show: true
  }
};
//# sourceMappingURL=index.js.map
