var __assign = this && this.__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

var __rest = this && this.__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};

import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import Draggable from 'react-draggable';
import Icon from "../icon";
import "./style/draggable-wrap.css";
import { randomUuid } from "../_utils/stringUtil";
var prefixCls = 'dmc-draggable-wrap';
export var DraggableWrap = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var children = props.children,
      hideHandler = props.hideHandler,
      draggableProps = __rest(props, ["children", "hideHandler"]);

  var hasHandle = ('handle' in draggableProps);
  var rand = React.useMemo(function () {
    return randomUuid();
  }, []);
  return _jsx(Draggable, __assign({}, draggableProps, {
    /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
    ref: ref,
    handle: hasHandle ? draggableProps.handle : "div[data-handle=\"" + rand + "\"]"
  }, {
    children: hasHandle ? children : _jsxs("div", __assign({
      className: prefixCls
    }, {
      children: [!hideHandler && _jsx(Icon, {
        "data-handle": rand,
        icon: "drag-handle-cornor",
        className: prefixCls + "-handle"
      }, void 0), children]
    }), void 0)
  }), void 0);
});
DraggableWrap.defaultProps = {
  axis: 'both',
  bounds: 'body'
};
DraggableWrap.displayName = 'DraggableWrap';
export default DraggableWrap;
var DraggableWrapMemo = /*#__PURE__*/React.memo(DraggableWrap);
DraggableWrapMemo.displayName = 'DraggableWrapMemo';
export { DraggableWrapMemo };

