var _excluded = ["map", "value", "onDragStart", "onDragEnd"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react';

// 中心点标注
var CenterMarker = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var map = _ref.map,
    value = _ref.value,
    onDragStart = _ref.onDragStart,
    onDragEnd = _ref.onDragEnd,
    props = _objectWithoutProperties(_ref, _excluded);
  var rootRef = useRef(null);

  // 节点
  useImperativeHandle(ref, function () {
    return {
      rootDOM: rootRef.current,
      getRootDOM: function getRootDOM() {
        return rootRef.current;
      }
    };
  });
  useEffect(function () {
    if (!(value !== null && value !== void 0 && value.longitude) || !(value !== null && value !== void 0 && value.latitude)) {
      return;
    }
    // Destroy clear center marker
    map.clearCenterMarker();
    map.onDragStart = null;
    map.onDragEnd = null;

    // Add center marker and drag interaction
    map.addCenterMarker({
      longitude: value.longitude,
      latitude: value.latitude,
      type: value.type,
      icon: value === null || value === void 0 ? void 0 : value.icon
    });
    map.onDragStart = function (map) {
      if (onDragEnd) {
        var _rootRef$current, _rootRef$current$remo;
        rootRef === null || rootRef === void 0 || (_rootRef$current = rootRef.current) === null || _rootRef$current === void 0 || (_rootRef$current = _rootRef$current.classList) === null || _rootRef$current === void 0 || (_rootRef$current$remo = _rootRef$current.remove) === null || _rootRef$current$remo === void 0 || _rootRef$current$remo.call(_rootRef$current, 'active');
      }
      onDragStart && onDragStart(map);
    };
    map.onDragEnd = function (map) {
      if (onDragEnd) {
        var _rootRef$current2, _rootRef$current2$add;
        rootRef === null || rootRef === void 0 || (_rootRef$current2 = rootRef.current) === null || _rootRef$current2 === void 0 || (_rootRef$current2 = _rootRef$current2.classList) === null || _rootRef$current2 === void 0 || (_rootRef$current2$add = _rootRef$current2.add) === null || _rootRef$current2$add === void 0 || _rootRef$current2$add.call(_rootRef$current2, 'active');
        onDragEnd(map);
      }
    };

    // eslint-disable-next-line
  }, [value]);

  // 拖拽过程时显示的点, 拖拽结束隐藏
  return /*#__PURE__*/React.createElement("span", _extends({}, props, {
    className: "map-center-marker active".concat(props !== null && props !== void 0 && props.className ? ' ' + props.className : ''),
    ref: rootRef
  }));
});
export default CenterMarker;