import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/DragAndDrop/docs/SortableListBase/SingleAreaListWithAnimation/SingleAreaListWithAnimation.jsx";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(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; })(); }
import React from 'react';
import classNames from 'classnames';
import { stVars } from '../../../../Foundation/stylable/easing.st.css';
import { dndStyles as defaultDndStyles, SortableListBase } from '../../../..';
import { classes } from './SingleAreaListWithAnimation.st.css';
var generateId = function generateId() {
  return Math.floor(Math.random() * 100000);
};
var SingleAreaListWithAnimation = /*#__PURE__*/function (_React$Component) {
  function SingleAreaListWithAnimation() {
    var _this;
    _classCallCheck(this, SingleAreaListWithAnimation);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, SingleAreaListWithAnimation, [].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 = _toConsumableArray(_this.state.items);
      nextItems.splice.apply(nextItems, [addedIndex, 0].concat(_toConsumableArray(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 = classNames(classNames(defaultDndStyles.item, classes.item), _defineProperty(_defineProperty({}, classNames(defaultDndStyles.itemPlaceholder, classes.placeholder), isPlaceholder), classNames(defaultDndStyles.itemPreview, classes.preview), isPreview));
      return /*#__PURE__*/React.createElement("div", {
        className: _classes,
        "data-hook": "item-".concat(id),
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 66,
          columnNumber: 7
        }
      }, item.text, _this.props.withHandle ? _this.renderHandle({
        connectHandle: connectHandle,
        id: id,
        isPlaceholder: isPlaceholder
      }) : null);
    };
    return _this;
  }
  _inherits(SingleAreaListWithAnimation, _React$Component);
  return _createClass(SingleAreaListWithAnimation, [{
    key: "renderHandle",
    value: function renderHandle(_ref3) {
      var connectHandle = _ref3.connectHandle,
        id = _ref3.id,
        isPlaceholder = _ref3.isPlaceholder;
      return connectHandle(/*#__PURE__*/React.createElement("div", {
        className: classes.handle,
        style: {
          opacity: isPlaceholder ? 0 : 1
        },
        "data-hook": "card-".concat(id, "-handle"),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 45,
          columnNumber: 7
        }
      }, "Drag Handle"));
    }
  }, {
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement("div", {
        className: classes.root,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 77,
          columnNumber: 7
        }
      }, /*#__PURE__*/React.createElement("h3", {
        className: classes.title,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 78,
          columnNumber: 9
        }
      }, "Draggable Area"), /*#__PURE__*/React.createElement(SortableListBase, {
        withHandle: this.props.withHandle,
        className: classes.sortableListBase,
        containerId: "single-area-1",
        dataHook: "list-single-area",
        items: this.state.items,
        renderItem: this.renderItem,
        onDrop: this.handleDrop,
        animationDuration: 500,
        animationTiming: stVars['ease-7'],
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 79,
          columnNumber: 9
        }
      }));
    }
  }]);
}(React.Component);
export { SingleAreaListWithAnimation as default };