"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _ = require("../../../..");
var _MultiAreaListPreventDroppingSt = require("./MultiAreaListPreventDropping.st.css");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/DragAndDrop/docs/SortableListBase/MultiAreaListPreventOfDropping/MultiAreaListPreventDropping.jsx";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var generateStateForContainer = function generateStateForContainer(length, startIndex) {
  var res = [];
  for (var i = 0; i < length; i++) {
    res.push({
      id: 'item' + (startIndex + i),
      text: "Drag object ".concat(startIndex + i)
    });
  }
  return res;
};
var copy = function copy(value) {
  return JSON.parse(JSON.stringify(value));
};

/**
 * An example multi list dnd.
 */
var MultiAreaListPreventDropping = exports["default"] = /*#__PURE__*/function (_React$Component) {
  function MultiAreaListPreventDropping() {
    var _this;
    (0, _classCallCheck2["default"])(this, MultiAreaListPreventDropping);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, MultiAreaListPreventDropping, [].concat(args));
    _this.state = {
      multiArea1: generateStateForContainer(4, 1),
      multiArea2: generateStateForContainer(4, 5)
    };
    _this.handleDrop = function (_ref) {
      var removedIndex = _ref.removedIndex,
        addedIndex = _ref.addedIndex,
        removedFromContainerId = _ref.removedFromContainerId,
        addedToContainerId = _ref.addedToContainerId,
        payload = _ref.payload;
      var nextState = copy(_this.state);
      nextState[removedFromContainerId].splice(removedIndex, 1);
      nextState[addedToContainerId].splice(addedIndex, 0, payload);
      _this.setState(_objectSpread({}, nextState));
    };
    _this.renderItem = function (_ref2) {
      var isPlaceholder = _ref2.isPlaceholder,
        isPreview = _ref2.isPreview,
        id = _ref2.id,
        item = _ref2.item,
        previewStyles = _ref2.previewStyles;
      var _classes = (0, _classnames["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, (0, _classnames["default"])(_.dndStyles.itemPlaceholder, _MultiAreaListPreventDroppingSt.classes.itemPlaceholder), isPlaceholder), (0, _classnames["default"])(_.dndStyles.itemPreview, _MultiAreaListPreventDroppingSt.classes.itemPreview), isPreview), (0, _classnames["default"])(_.dndStyles.item, _MultiAreaListPreventDroppingSt.classes.item));
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: _classes,
        style: previewStyles,
        "data-hook": "item-".concat(id),
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 58,
          columnNumber: 7
        }
      }, item.text);
    };
    return _this;
  }
  (0, _inherits2["default"])(MultiAreaListPreventDropping, _React$Component);
  return (0, _createClass2["default"])(MultiAreaListPreventDropping, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react["default"].createElement(_.DragDropContextProvider, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 66,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: _MultiAreaListPreventDroppingSt.classes.root,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 67,
          columnNumber: 9
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 68,
          columnNumber: 11
        }
      }, /*#__PURE__*/_react["default"].createElement("h4", {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 69,
          columnNumber: 13
        }
      }, "Drop is not allowed here"), /*#__PURE__*/_react["default"].createElement(_.SortableListBase, {
        className: (0, _classnames["default"])(_.dndStyles.list, _MultiAreaListPreventDroppingSt.classes.list),
        dataHook: "list-multi-area",
        groupName: "multi-area",
        containerId: "multiArea1",
        items: this.state.multiArea1,
        renderItem: this.renderItem,
        droppable: false,
        onDrop: this.handleDrop,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 70,
          columnNumber: 13
        }
      })), /*#__PURE__*/_react["default"].createElement("div", {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 81,
          columnNumber: 11
        }
      }, /*#__PURE__*/_react["default"].createElement("h4", {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 82,
          columnNumber: 13
        }
      }, "You can drop here"), /*#__PURE__*/_react["default"].createElement(_.SortableListBase, {
        className: (0, _classnames["default"])(_.dndStyles.list, _MultiAreaListPreventDroppingSt.classes.list),
        dataHook: "list-multi-area",
        groupName: "multi-area",
        containerId: "multiArea2",
        items: this.state.multiArea2,
        renderItem: this.renderItem,
        onDrop: this.handleDrop,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 83,
          columnNumber: 13
        }
      }))));
    }
  }]);
}(_react["default"].Component);