"use strict";
const React = require("react");
const index = require("../../ConfigProvider/index.js");
const classNames = require("../../_util/classNames.js");
const item = require("./item.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
function Draggable(props) {
  var getPrefixCls = React.useContext(index.ConfigContext).getPrefixCls;
  var prefixCls = getPrefixCls("draggable");
  var className = props.className, children = props.children, direction = props.direction, onIndexChange = props.onIndexChange, itemWrapperStyle = props.itemWrapperStyle;
  var _a = __read(React.useState(null), 2), dragItemIndex = _a[0], setDragItemIndex = _a[1];
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
    className: classNames(prefixCls, className),
    children: React__default.default.Children.map(children, function(child, index2) {
      return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(item, {
        style: itemWrapperStyle,
        prefixCls,
        direction,
        onDragStart: function() {
          return setDragItemIndex(index2);
        },
        onDragEnd: function() {
          return setDragItemIndex(null);
        },
        onDrop: function(_, dropPosition) {
          var prevIndex = dragItemIndex;
          var nextIndex = dropPosition === "left" || dropPosition === "top" ? index2 : index2 + 1;
          if (onIndexChange && prevIndex !== nextIndex) {
            onIndexChange(nextIndex, prevIndex);
          }
        },
        children: child
      });
    })
  });
}
Draggable.defaultProps = {
  direction: "vertical"
};
module.exports = Draggable;
//# sourceMappingURL=index.js.map
