"use strict";
const React = require("react");
const classNames = require("../../_util/classNames.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");
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 Item(props) {
  var _a;
  var prefixCls = props.prefixCls, style = props.style, children = props.children, direction = props.direction, disabled = props.disabled, droppable = props.droppable, onDrop = props.onDrop, onDragStart = props.onDragStart, onDragEnd = props.onDragEnd, onDragOver = props.onDragOver, onDragLeave = props.onDragLeave;
  var refItem = React.useRef(null);
  var refDraggedTimer = React.useRef(null);
  var _b = __read(React.useState("none"), 2), dragStatus = _b[0], setDragStatus = _b[1];
  var _c = __read(React.useState(false), 2), dragOver = _c[0], setDragOver = _c[1];
  var _d = __read(React.useState(null), 2), dragPosition = _d[0], setDragPosition = _d[1];
  React.useEffect(function() {
    return function() {
      refDraggedTimer.current && clearTimeout(refDraggedTimer.current);
    };
  }, []);
  React.useEffect(function() {
    if (dragStatus === "dragged") {
      refDraggedTimer.current = setTimeout(function() {
        return setDragStatus("none");
      }, 1e3);
    }
  }, [dragStatus]);
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("li", {
    draggable: true,
    ref: refItem,
    style,
    className: classNames(prefixCls + "-item", (_a = {}, _a[prefixCls + "-item-" + dragStatus] = dragStatus !== "none", _a[prefixCls + "-item-gap-" + dragPosition] = dragPosition, _a[prefixCls + "-item-disabled"] = disabled, _a[prefixCls + "-item-dragover"] = dragOver, _a)),
    onDragStart: function(event) {
      event.stopPropagation();
      setDragStatus("dragging");
      try {
        event.dataTransfer.setData("text/plain", "");
      } catch (error) {
      }
      onDragStart && onDragStart(event);
    },
    onDragEnd: function(event) {
      event.stopPropagation();
      setDragOver(false);
      setDragStatus("dragged");
      onDragEnd && onDragEnd(event);
    },
    onDragOver: function(event) {
      if (droppable) {
        event.stopPropagation();
        event.preventDefault();
        var rect = refItem.current.getBoundingClientRect();
        if (direction === "vertical") {
          setDragPosition(event.pageY > window.pageYOffset + rect.top + rect.height / 2 ? "bottom" : "top");
        } else {
          setDragPosition(event.pageX > window.pageXOffset + rect.left + rect.width / 2 ? "right" : "left");
        }
        setDragOver(true);
        onDragOver && onDragOver(event);
      }
    },
    onDragLeave: function(event) {
      if (droppable) {
        event.stopPropagation();
        setDragOver(false);
        onDragLeave && onDragLeave(event);
      }
    },
    onDrop: function(event) {
      if (droppable) {
        event.stopPropagation();
        event.preventDefault();
        setDragOver(false);
        setDragPosition(null);
        setDragStatus("none");
        onDrop && onDrop(event, dragPosition);
      }
    },
    children
  });
}
Item.defaultProps = {
  droppable: true
};
module.exports = Item;
//# sourceMappingURL=item.js.map
