var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
import { d as dist } from "../../../../../../_virtual/index2.js";
import require$$0 from "../../../../../../_virtual/sortable.esm.js";
import "../node_modules/classnames/index.js";
import React__default from "react";
import require$$3 from "../../../../../../_virtual/tiny-invariant.esm.js";
import { c as classnames } from "../../../../../../_virtual/index3.js";
(function(module) {
  var $8zHUo$sortablejs = require$$0;
  var $8zHUo$classnames = classnames.exports;
  var $8zHUo$react = React__default;
  var $8zHUo$tinyinvariant = require$$3;
  function $parcel$interopDefault(a) {
    return a && a.__esModule ? a.default : a;
  }
  function $parcel$export(e, n, v, s) {
    Object.defineProperty(e, n, { get: v, set: s, enumerable: true, configurable: true });
  }
  function $parcel$exportWildcard(dest, source) {
    Object.keys(source).forEach(function(key) {
      if (key === "default" || key === "__esModule" || dest.hasOwnProperty(key)) {
        return;
      }
      Object.defineProperty(dest, key, {
        enumerable: true,
        get: function get() {
          return source[key];
        }
      });
    });
    return dest;
  }
  $parcel$export(module.exports, "Sortable", () => $882b6d93070905b3$re_export$Sortable);
  $parcel$export(module.exports, "Direction", () => $882b6d93070905b3$re_export$Direction);
  $parcel$export(module.exports, "DOMRect", () => $882b6d93070905b3$re_export$DOMRect);
  $parcel$export(module.exports, "GroupOptions", () => $882b6d93070905b3$re_export$GroupOptions);
  $parcel$export(module.exports, "MoveEvent", () => $882b6d93070905b3$re_export$MoveEvent);
  $parcel$export(module.exports, "Options", () => $882b6d93070905b3$re_export$Options);
  $parcel$export(module.exports, "PullResult", () => $882b6d93070905b3$re_export$PullResult);
  $parcel$export(module.exports, "PutResult", () => $882b6d93070905b3$re_export$PutResult);
  $parcel$export(module.exports, "SortableEvent", () => $882b6d93070905b3$re_export$SortableEvent);
  $parcel$export(module.exports, "SortableOptions", () => $882b6d93070905b3$re_export$SortableOptions);
  $parcel$export(module.exports, "Utils", () => $882b6d93070905b3$re_export$Utils);
  $parcel$export(module.exports, "ReactSortable", () => $7fe8e3ea572bda7a$export$11bbed9ee0012c13);
  function $eb03e74f8f7db1f3$export$1d0aa160432dfea5(node) {
    if (node.parentElement !== null)
      node.parentElement.removeChild(node);
  }
  function $eb03e74f8f7db1f3$export$6d240faa51aa562f(parent, newChild, index) {
    const refChild = parent.children[index] || null;
    parent.insertBefore(newChild, refChild);
  }
  function $eb03e74f8f7db1f3$export$77f49a256021c8de(customs) {
    customs.forEach((curr) => $eb03e74f8f7db1f3$export$1d0aa160432dfea5(curr.element));
  }
  function $eb03e74f8f7db1f3$export$a6177d5829f70ebc(customs) {
    customs.forEach((curr) => {
      $eb03e74f8f7db1f3$export$6d240faa51aa562f(curr.parentElement, curr.element, curr.oldIndex);
    });
  }
  function $eb03e74f8f7db1f3$export$4655efe700f887a(evt, list) {
    const mode = $eb03e74f8f7db1f3$export$1fc0f6205829e19c(evt);
    const parentElement = {
      parentElement: evt.from
    };
    let custom = [];
    switch (mode) {
      case "normal":
        const item = {
          element: evt.item,
          newIndex: evt.newIndex,
          oldIndex: evt.oldIndex,
          parentElement: evt.from
        };
        custom = [
          item
        ];
        break;
      case "swap":
        const drag = {
          element: evt.item,
          oldIndex: evt.oldIndex,
          newIndex: evt.newIndex,
          ...parentElement
        };
        const swap = {
          element: evt.swapItem,
          oldIndex: evt.newIndex,
          newIndex: evt.oldIndex,
          ...parentElement
        };
        custom = [
          drag,
          swap
        ];
        break;
      case "multidrag":
        custom = evt.oldIndicies.map((curr, index) => ({
          element: curr.multiDragElement,
          oldIndex: curr.index,
          newIndex: evt.newIndicies[index].index,
          ...parentElement
        }));
        break;
    }
    const customs = $eb03e74f8f7db1f3$export$bc06a3af7dc65f53(custom, list);
    return customs;
  }
  function $eb03e74f8f7db1f3$export$c25cf8080bd305ec(normalized, list) {
    const a = $eb03e74f8f7db1f3$export$be2da95e6167b0bd(normalized, list);
    const b = $eb03e74f8f7db1f3$export$eca851ee65ae17e4(normalized, a);
    return b;
  }
  function $eb03e74f8f7db1f3$export$be2da95e6167b0bd(normalized, list) {
    const newList = [
      ...list
    ];
    normalized.concat().reverse().forEach((curr) => newList.splice(curr.oldIndex, 1));
    return newList;
  }
  function $eb03e74f8f7db1f3$export$eca851ee65ae17e4(normalized, list, evt, clone) {
    const newList = [
      ...list
    ];
    normalized.forEach((curr) => {
      const newItem = clone && evt && clone(curr.item, evt);
      newList.splice(curr.newIndex, 0, newItem || curr.item);
    });
    return newList;
  }
  function $eb03e74f8f7db1f3$export$1fc0f6205829e19c(evt) {
    if (evt.oldIndicies && evt.oldIndicies.length > 0)
      return "multidrag";
    if (evt.swapItem)
      return "swap";
    return "normal";
  }
  function $eb03e74f8f7db1f3$export$bc06a3af7dc65f53(inputs, list) {
    const normalized = inputs.map((curr) => ({
      ...curr,
      item: list[curr.oldIndex]
    })).sort((a, b) => a.oldIndex - b.oldIndex);
    return normalized;
  }
  function $eb03e74f8f7db1f3$export$7553c81e62e31b7e(props) {
    const { list, setList, children, tag, style, className, clone, onAdd, onChange, onChoose, onClone, onEnd, onFilter, onRemove, onSort, onStart, onUnchoose, onUpdate, onMove, onSpill, onSelect, onDeselect, ...options } = props;
    return options;
  }
  const $7fe8e3ea572bda7a$var$store = {
    dragging: null
  };
  class $7fe8e3ea572bda7a$export$11bbed9ee0012c13 extends $8zHUo$react.Component {
    constructor(props) {
      super(props);
      this.ref = /* @__PURE__ */ (0, $8zHUo$react.createRef)();
      const newList = [
        ...props.list
      ].map((item) => Object.assign(item, {
        chosen: false,
        selected: false
      }));
      props.setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
      $parcel$interopDefault($8zHUo$tinyinvariant)(
        !props.plugins,
        `
Plugins prop is no longer supported.
Instead, mount it with "Sortable.mount(new MultiDrag())"
Please read the updated README.md at https://github.com/SortableJS/react-sortablejs.
      `
      );
    }
    componentDidMount() {
      if (this.ref.current === null)
        return;
      const newOptions = this.makeOptions();
      $parcel$interopDefault($8zHUo$sortablejs).create(this.ref.current, newOptions);
    }
    componentDidUpdate(prevProps) {
      if (prevProps.disabled !== this.props.disabled && this.sortable)
        this.sortable.option("disabled", this.props.disabled);
    }
    render() {
      const { tag, style, className, id } = this.props;
      const classicProps = {
        style,
        className,
        id
      };
      const newTag = !tag || tag === null ? "div" : tag;
      return /* @__PURE__ */ (0, $8zHUo$react.createElement)(newTag, {
        ref: this.ref,
        ...classicProps
      }, this.getChildren());
    }
    getChildren() {
      const { children, dataIdAttr, selectedClass = "sortable-selected", chosenClass = "sortable-chosen", dragClass = "sortable-drag", fallbackClass = "sortable-falback", ghostClass = "sortable-ghost", swapClass = "sortable-swap-highlight", filter = "sortable-filter", list } = this.props;
      if (!children || children == null)
        return null;
      const dataid = dataIdAttr || "data-id";
      return $8zHUo$react.Children.map(children, (child, index) => {
        if (child === void 0)
          return void 0;
        const item = list[index] || {};
        const { className: prevClassName } = child.props;
        const filtered = typeof filter === "string" && {
          [filter.replace(".", "")]: !!item.filtered
        };
        const className = $parcel$interopDefault($8zHUo$classnames)(prevClassName, {
          [selectedClass]: item.selected,
          [chosenClass]: item.chosen,
          ...filtered
        });
        return /* @__PURE__ */ (0, $8zHUo$react.cloneElement)(child, {
          [dataid]: child.key,
          className
        });
      });
    }
    get sortable() {
      const el = this.ref.current;
      if (el === null)
        return null;
      const key = Object.keys(el).find((k) => k.includes("Sortable"));
      if (!key)
        return null;
      return el[key];
    }
    makeOptions() {
      const DOMHandlers = [
        "onAdd",
        "onChoose",
        "onDeselect",
        "onEnd",
        "onRemove",
        "onSelect",
        "onSpill",
        "onStart",
        "onUnchoose",
        "onUpdate"
      ];
      const NonDOMHandlers = [
        "onChange",
        "onClone",
        "onFilter",
        "onSort"
      ];
      const newOptions = $eb03e74f8f7db1f3$export$7553c81e62e31b7e(this.props);
      DOMHandlers.forEach((name) => newOptions[name] = this.prepareOnHandlerPropAndDOM(name));
      NonDOMHandlers.forEach((name) => newOptions[name] = this.prepareOnHandlerProp(name));
      const onMove1 = (evt, originalEvt) => {
        const { onMove } = this.props;
        const defaultValue = evt.willInsertAfter || -1;
        if (!onMove)
          return defaultValue;
        const result = onMove(evt, originalEvt, this.sortable, $7fe8e3ea572bda7a$var$store);
        if (typeof result === "undefined")
          return false;
        return result;
      };
      return {
        ...newOptions,
        onMove: onMove1
      };
    }
    prepareOnHandlerPropAndDOM(evtName) {
      return (evt) => {
        this.callOnHandlerProp(evt, evtName);
        this[evtName](evt);
      };
    }
    prepareOnHandlerProp(evtName) {
      return (evt) => {
        this.callOnHandlerProp(evt, evtName);
      };
    }
    callOnHandlerProp(evt, evtName) {
      const propEvent = this.props[evtName];
      if (propEvent)
        propEvent(evt, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
    onAdd(evt) {
      const { list, setList, clone } = this.props;
      const otherList = [
        ...$7fe8e3ea572bda7a$var$store.dragging.props.list
      ];
      const customs = $eb03e74f8f7db1f3$export$4655efe700f887a(evt, otherList);
      $eb03e74f8f7db1f3$export$77f49a256021c8de(customs);
      const newList = $eb03e74f8f7db1f3$export$eca851ee65ae17e4(customs, list, evt, clone).map((item) => Object.assign(item, {
        selected: false
      }));
      setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
    onRemove(evt) {
      const { list, setList } = this.props;
      const mode = $eb03e74f8f7db1f3$export$1fc0f6205829e19c(evt);
      const customs = $eb03e74f8f7db1f3$export$4655efe700f887a(evt, list);
      $eb03e74f8f7db1f3$export$a6177d5829f70ebc(customs);
      let newList = [
        ...list
      ];
      if (evt.pullMode !== "clone")
        newList = $eb03e74f8f7db1f3$export$be2da95e6167b0bd(customs, newList);
      else {
        let customClones = customs;
        switch (mode) {
          case "multidrag":
            customClones = customs.map((item, index) => ({
              ...item,
              element: evt.clones[index]
            }));
            break;
          case "normal":
            customClones = customs.map((item) => ({
              ...item,
              element: evt.clone
            }));
            break;
          case "swap":
          default:
            $parcel$interopDefault($8zHUo$tinyinvariant)(true, `mode "${mode}" cannot clone. Please remove "props.clone" from <ReactSortable/> when using the "${mode}" plugin`);
        }
        $eb03e74f8f7db1f3$export$77f49a256021c8de(customClones);
        customs.forEach((curr) => {
          const index = curr.oldIndex;
          const newItem = this.props.clone(curr.item, evt);
          newList.splice(index, 1, newItem);
        });
      }
      newList = newList.map((item) => Object.assign(item, {
        selected: false
      }));
      setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
    onUpdate(evt) {
      const { list, setList } = this.props;
      const customs = $eb03e74f8f7db1f3$export$4655efe700f887a(evt, list);
      $eb03e74f8f7db1f3$export$77f49a256021c8de(customs);
      $eb03e74f8f7db1f3$export$a6177d5829f70ebc(customs);
      const newList = $eb03e74f8f7db1f3$export$c25cf8080bd305ec(customs, list);
      return setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
    onStart() {
      $7fe8e3ea572bda7a$var$store.dragging = this;
    }
    onEnd() {
      $7fe8e3ea572bda7a$var$store.dragging = null;
    }
    onChoose(evt) {
      const { list, setList } = this.props;
      const newList = list.map((item, index) => {
        let newItem = item;
        if (index === evt.oldIndex)
          newItem = Object.assign(item, {
            chosen: true
          });
        return newItem;
      });
      setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
    onUnchoose(evt) {
      const { list, setList } = this.props;
      const newList = list.map((item, index) => {
        let newItem = item;
        if (index === evt.oldIndex)
          newItem = Object.assign(newItem, {
            chosen: false
          });
        return newItem;
      });
      setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
    onSpill(evt) {
      const { removeOnSpill, revertOnSpill } = this.props;
      if (removeOnSpill && !revertOnSpill)
        $eb03e74f8f7db1f3$export$1d0aa160432dfea5(evt.item);
    }
    onSelect(evt) {
      const { list, setList } = this.props;
      const newList = list.map((item) => Object.assign(item, {
        selected: false
      }));
      evt.newIndicies.forEach((curr) => {
        const index = curr.index;
        if (index === -1) {
          console.log(`"${evt.type}" had indice of "${curr.index}", which is probably -1 and doesn't usually happen here.`);
          console.log(evt);
          return;
        }
        newList[index].selected = true;
      });
      setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
    onDeselect(evt) {
      const { list, setList } = this.props;
      const newList = list.map((item) => Object.assign(item, {
        selected: false
      }));
      evt.newIndicies.forEach((curr) => {
        const index = curr.index;
        if (index === -1)
          return;
        newList[index].selected = true;
      });
      setList(newList, this.sortable, $7fe8e3ea572bda7a$var$store);
    }
  }
  __publicField($7fe8e3ea572bda7a$export$11bbed9ee0012c13, "defaultProps", {
    clone: (item) => item
  });
  var $faefaad95e5fcca0$exports = {};
  $parcel$exportWildcard(module.exports, $faefaad95e5fcca0$exports);
})(dist);
//# sourceMappingURL=index.js.map
