"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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
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 _ListWithDelaySt = require("./ListWithDelay.st.css");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/DragAndDrop/docs/SortableListBase/ListWithDelay/ListWithDelay.jsx";
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 generateId = function generateId() {
  return Math.floor(Math.random() * 100000);
};
var ListWithDelay = exports["default"] = /*#__PURE__*/function (_React$Component) {
  function ListWithDelay() {
    var _this;
    (0, _classCallCheck2["default"])(this, ListWithDelay);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, ListWithDelay, [].concat(args));
    _this.state = {
      items: [{
        id: generateId(),
        text: 'Item 1'
      }, {
        id: generateId(),
        text: 'Item 2'
      }, {
        id: generateId(),
        text: 'Item 3'
      }, {
        id: generateId(),
        text: 'Item 4'
      }, {
        id: generateId(),
        text: 'Item 5'
      }]
    };
    _this.handleDrop = function (_ref) {
      var removedIndex = _ref.removedIndex,
        addedIndex = _ref.addedIndex;
      var nextItems = (0, _toConsumableArray2["default"])(_this.state.items);
      nextItems.splice.apply(nextItems, [addedIndex, 0].concat((0, _toConsumableArray2["default"])(nextItems.splice(removedIndex, 1))));
      _this.setState({
        items: nextItems
      });
    };
    _this.renderItem = function (_ref2) {
      var isPlaceholder = _ref2.isPlaceholder,
        isPreview = _ref2.isPreview,
        id = _ref2.id,
        connectHandle = _ref2.connectHandle,
        item = _ref2.item;
      var _classes = (0, _classnames["default"])((0, _classnames["default"])(_.dndStyles.item, _ListWithDelaySt.classes.item), (0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, (0, _classnames["default"])(_.dndStyles.itemPlaceholder, _ListWithDelaySt.classes.placeholder), isPlaceholder), (0, _classnames["default"])(_.dndStyles.itemPreview, _ListWithDelaySt.classes.preview), isPreview));
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: _classes,
        "data-hook": "item-".concat(id),
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 53,
          columnNumber: 7
        }
      }, item.text, _this.props.withHandle ? _this.renderHandle({
        connectHandle: connectHandle,
        id: id,
        isPlaceholder: isPlaceholder
      }) : null);
    };
    return _this;
  }
  (0, _inherits2["default"])(ListWithDelay, _React$Component);
  return (0, _createClass2["default"])(ListWithDelay, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: _ListWithDelaySt.classes.root,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 64,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement("h3", {
        className: _ListWithDelaySt.classes.title,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 65,
          columnNumber: 9
        }
      }, "Draggable Area"), /*#__PURE__*/_react["default"].createElement(_.SortableListBase, {
        withHandle: this.props.withHandle,
        className: _ListWithDelaySt.classes.sortableListBase,
        containerId: "single-area-1",
        dataHook: "list-single-area",
        items: this.state.items,
        renderItem: this.renderItem,
        onDrop: this.handleDrop,
        delay: 400,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 66,
          columnNumber: 9
        }
      }));
    }
  }]);
}(_react["default"].Component);