"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"));
require("./style");
var _useProps2 = _interopRequireDefault(require("../use-props"));
var _ScaleDenominator = _interopRequireDefault(require("./ScaleDenominator"));
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); }
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; } // Test.jsx
// 获取地图容器的像素尺寸
function getMapSizeInPx(map) {
  var viewport = map.getViewport();
  var rect = viewport.getBoundingClientRect();
  return {
    width: rect.width,
    height: rect.height
  };
}

// 示例：在控制台输出当前地图尺寸
var Test = function Test() {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map;
  var _useState = (0, _react.useState)('none'),
    _useState2 = _slicedToArray(_useState, 2),
    dispaly = _useState2[0],
    setDispaly = _useState2[1];
  var _useState3 = (0, _react.useState)(0),
    _useState4 = _slicedToArray(_useState3, 2),
    clickCount = _useState4[0],
    setClickCount = _useState4[1];
  var _useState5 = (0, _react.useState)(false),
    _useState6 = _slicedToArray(_useState5, 2),
    isDragging = _useState6[0],
    setIsDragging = _useState6[1];
  var _useState7 = (0, _react.useState)({
      x: 0,
      y: 0
    }),
    _useState8 = _slicedToArray(_useState7, 2),
    dragStart = _useState8[0],
    setDragStart = _useState8[1];
  var _useState9 = (0, _react.useState)({
      x: 100,
      y: 100
    }),
    _useState0 = _slicedToArray(_useState9, 2),
    boxPosition = _useState0[0],
    setBoxPosition = _useState0[1];
  var boxRef = (0, _react.useRef)(null);
  var lastClickTime = (0, _react.useRef)(0);
  (0, _react.useEffect)(function () {
    if (!map) return;
    setBoxPosition({
      x: getMapSizeInPx(map).width / 2 - 100,
      y: getMapSizeInPx(map).height / 2 - 75
    });
    var handleClick = function handleClick() {
      var currentTime = Date.now();
      // 检查两次点击间隔是否小于1秒(1000毫秒)
      if (currentTime - lastClickTime.current < 1000) {
        var newCount = clickCount + 1;
        setClickCount(newCount);
        if (newCount >= 10) {
          setDispaly('block');
        }
      }
      // 更新上次点击时间
      lastClickTime.current = currentTime;
    };
    map.on('click', handleClick);
    return function () {
      map.un('click', handleClick);
    };
  }, [map, clickCount]);
  // 处理拖动开始
  var handleDragStart = function handleDragStart(e) {
    setIsDragging(true);
    setDragStart({
      x: e.clientX - boxPosition.x,
      y: e.clientY - boxPosition.y
    });
    e.preventDefault();
  };

  // 处理拖动过程
  var handleDrag = function handleDrag(e) {
    if (isDragging) {
      setBoxPosition({
        x: e.clientX - dragStart.x,
        y: e.clientY - dragStart.y
      });
    }
  };

  // 处理拖动结束
  var handleDragEnd = function handleDragEnd() {
    setIsDragging(false);
  };

  // 在useEffect中添加鼠标事件监听
  (0, _react.useEffect)(function () {
    if (isDragging) {
      document.addEventListener('mousemove', handleDrag);
      document.addEventListener('mouseup', handleDragEnd);
    } else {
      document.removeEventListener('mousemove', handleDrag);
      document.removeEventListener('mouseup', handleDragEnd);
    }
    return function () {
      document.removeEventListener('mousemove', handleDrag);
      document.removeEventListener('mouseup', handleDragEnd);
    };
  }, [isDragging, dragStart]);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, dispaly === 'block' && /*#__PURE__*/_react["default"].createElement("div", {
    ref: boxRef,
    style: {
      position: 'absolute',
      top: "".concat(boxPosition.y, "px"),
      left: "".concat(boxPosition.x, "px"),
      width: '200px',
      height: '150px',
      border: '2px solid #333',
      backgroundColor: 'rgba(255, 255, 255, 0.8)',
      cursor: 'move',
      resize: 'both',
      overflow: 'auto',
      zIndex: 1000
    },
    onMouseDown: handleDragStart
  }, /*#__PURE__*/_react["default"].createElement(_ScaleDenominator["default"], null)));
};
var _default = exports["default"] = Test;
//# sourceMappingURL=Test.js.map
