"use strict";

Liferay.Loader.define("site-navigation-item-selector-web$dnd-core@11.1.3/dist/cjs/actions/dragDrop/drop", ['module', 'exports', 'require', '@site-navigation-item-selector-web$react-dnd/invariant', './types', '../../utils/js_utils'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.createDrop = createDrop;

    var _invariant = require("@site-navigation-item-selector-web$react-dnd/invariant");

    var _types = require("./types");

    var _js_utils = require("../../utils/js_utils");

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    function createDrop(manager) {
      return function drop() {
        var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
        var monitor = manager.getMonitor();
        var registry = manager.getRegistry();
        verifyInvariants(monitor);
        var targetIds = getDroppableTargets(monitor); // Multiple actions are dispatched here, which is why this doesn't return an action

        targetIds.forEach(function (targetId, index) {
          var dropResult = determineDropResult(targetId, index, registry, monitor);
          var action = {
            type: _types.DROP,
            payload: {
              dropResult: _objectSpread(_objectSpread({}, options), dropResult)
            }
          };
          manager.dispatch(action);
        });
      };
    }

    function verifyInvariants(monitor) {
      (0, _invariant.invariant)(monitor.isDragging(), 'Cannot call drop while not dragging.');
      (0, _invariant.invariant)(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.');
    }

    function determineDropResult(targetId, index, registry, monitor) {
      var target = registry.getTarget(targetId);
      var dropResult = target ? target.drop(monitor, targetId) : undefined;
      verifyDropResultType(dropResult);

      if (typeof dropResult === 'undefined') {
        dropResult = index === 0 ? {} : monitor.getDropResult();
      }

      return dropResult;
    }

    function verifyDropResultType(dropResult) {
      (0, _invariant.invariant)(typeof dropResult === 'undefined' || (0, _js_utils.isObject)(dropResult), 'Drop result must either be an object or undefined.');
    }

    function getDroppableTargets(monitor) {
      var targetIds = monitor.getTargetIds().filter(monitor.canDropOnTarget, monitor);
      targetIds.reverse();
      return targetIds;
    }
  }
});
//# sourceMappingURL=drop.js.map