var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/DragSortList/index.tsx
var DragSortList_exports = {};
__export(DragSortList_exports, {
  SortableItem: () => SortableItem,
  default: () => Sortable
});
module.exports = __toCommonJS(DragSortList_exports);
var import_core = require("@dnd-kit/core");
var import_sortable = require("@dnd-kit/sortable");
var import_utilities = require("@dnd-kit/utilities");
var import_utils = require("@pisell/utils");
var import_react = __toESM(require("react"));
function Sortable({
  list = [],
  onChange,
  rowKey,
  children,
  activationConstraint
}) {
  const sensors = (0, import_core.useSensors)(
    (0, import_core.useSensor)(import_core.PointerSensor, {
      activationConstraint
    })
  );
  const getRowKey = (0, import_react.useCallback)(
    (row) => {
      if ((0, import_utils.isFunction)(rowKey)) {
        return rowKey(row);
      }
      return row[rowKey];
    },
    [rowKey]
  );
  const items = (0, import_react.useMemo)(() => {
    return list == null ? void 0 : list.map((item) => getRowKey(item));
  }, [list, rowKey]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_core.DndContext,
    {
      onDragEnd: ({ over, active }) => {
        if (active.id !== (over == null ? void 0 : over.id)) {
          const activeIndex = list == null ? void 0 : list.findIndex((i) => getRowKey(i) === active.id);
          const overIndex = list == null ? void 0 : list.findIndex((i) => getRowKey(i) === (over == null ? void 0 : over.id));
          onChange == null ? void 0 : onChange((0, import_sortable.arrayMove)(list, activeIndex, overIndex));
        }
      },
      sensors
    },
    /* @__PURE__ */ import_react.default.createElement(import_sortable.SortableContext, { items }, list.map((item, index) => /* @__PURE__ */ import_react.default.createElement(
      SortableItem,
      {
        key: getRowKey(item),
        id: getRowKey(item),
        item,
        index,
        disabled: !!(item == null ? void 0 : item.disabled)
      },
      children
    )))
  );
}
function SortableItem({
  id,
  index,
  item,
  children,
  disabled
}) {
  const {
    attributes,
    isSorting,
    listeners,
    setNodeRef,
    setActivatorNodeRef,
    transform,
    transition
  } = (0, import_sortable.useSortable)({
    id,
    disabled
  });
  return children({
    item,
    index,
    style: {
      transform: import_utilities.CSS.Transform.toString(
        transform && { ...transform, scaleY: 1 }
      ),
      transition
    },
    setActivatorNodeRef,
    listeners,
    attributes,
    props: {
      ref: setNodeRef
    }
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SortableItem
});
