import _defineProperty from "@babel/runtime/helpers/defineProperty";
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/MultiAreaListWithSortableColumns/MultiAreaListWithSortableColumns.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) { _defineProperty(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 = _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 { dndStyles as defaultDndStyles, SortableListBase, DragDropContextProvider } from '../../../..';
import { classes } from './MultiAreaListWithSortableColumns.st.css';
var generateStateForContainer = function generateStateForContainer(length, startIndex) {
  var res = [];
  for (var i = 0; i < length; i++) {
    res.push({
      id: 'item-new' + (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 MultiAreaListWithSortableColumns = /*#__PURE__*/function (_React$Component) {
  function MultiAreaListWithSortableColumns() {
    var _this;
    _classCallCheck(this, MultiAreaListWithSortableColumns);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, MultiAreaListWithSortableColumns, [].concat(args));
    _this.state = {
      columns: [{
        id: 'multiArea1',
        items: generateStateForContainer(4, 1),
        width: 250
      }, {
        id: 'multiArea2',
        items: generateStateForContainer(4, 5),
        width: 300
      }]
    };
    _this.handleDropCell = function (_ref) {
      var removedIndex = _ref.removedIndex,
        addedIndex = _ref.addedIndex,
        removedFromContainerId = _ref.removedFromContainerId,
        addedToContainerId = _ref.addedToContainerId,
        payload = _ref.payload;
      var nextState = copy(_this.state);
      nextState.columns.find(function (li) {
        return li.id === removedFromContainerId;
      }).items.splice(removedIndex, 1);
      nextState.columns.find(function (li) {
        return li.id === addedToContainerId;
      }).items.splice(addedIndex, 0, payload);
      _this.setState(_objectSpread({}, nextState));
    };
    _this.handleDropColumn = function (_ref2) {
      var removedIndex = _ref2.removedIndex,
        addedIndex = _ref2.addedIndex,
        payload = _ref2.payload;
      var nextState = copy(_this.state);
      nextState.columns.splice(removedIndex, 1);
      nextState.columns.splice(addedIndex, 0, payload);
      _this.setState(_objectSpread({}, nextState));
    };
    _this.renderCell = function (_ref3) {
      var isPlaceholder = _ref3.isPlaceholder,
        isPreview = _ref3.isPreview,
        id = _ref3.id,
        item = _ref3.item,
        previewStyles = _ref3.previewStyles,
        isListInDragState = _ref3.isListInDragState;
      var _classes = classNames(_defineProperty(_defineProperty(_defineProperty({}, classNames(defaultDndStyles.itemPlaceholder, classes.itemPlaceholder), isPlaceholder), classNames(defaultDndStyles.itemPreview, classes.itemPreview), isPreview), classes.isListInDragState, isListInDragState), classNames(defaultDndStyles.item, classes.item));
      return /*#__PURE__*/React.createElement("div", {
        className: _classes,
        style: previewStyles,
        "data-hook": "item-".concat(id),
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 88,
          columnNumber: 7
        }
      }, item.text);
    };
    _this.renderColumn = function (_ref4) {
      var isPlaceholder = _ref4.isPlaceholder,
        isPreview = _ref4.isPreview,
        item = _ref4.item,
        id = _ref4.id,
        previewStyles = _ref4.previewStyles;
      var _classes = classNames(_defineProperty(_defineProperty({}, classNames(defaultDndStyles.itemPlaceholder, classes.columnPlaceholder), isPlaceholder), classNames(defaultDndStyles.itemPreview), isPreview), classNames(defaultDndStyles.item));
      var width = item.width,
        items = item.items;
      return /*#__PURE__*/React.createElement("div", {
        className: _classes,
        style: _objectSpread(_objectSpread({}, previewStyles), {}, {
          width: width
        }),
        "data-hook": "column-".concat(id),
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 109,
          columnNumber: 7
        }
      }, /*#__PURE__*/React.createElement(SortableListBase, {
        dragPreview: isPreview,
        className: classNames(defaultDndStyles.list, classes.column),
        dataHook: "column-".concat(id),
        groupName: "multi-area",
        containerId: id,
        items: items,
        renderItem: _this.renderCell,
        onDrop: _this.handleDropCell,
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 114,
          columnNumber: 9
        }
      }));
    };
    return _this;
  }
  _inherits(MultiAreaListWithSortableColumns, _React$Component);
  return _createClass(MultiAreaListWithSortableColumns, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement(DragDropContextProvider, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 130,
          columnNumber: 7
        }
      }, /*#__PURE__*/React.createElement("div", {
        className: classes.root,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 131,
          columnNumber: 9
        }
      }, /*#__PURE__*/React.createElement(SortableListBase, {
        className: classNames(defaultDndStyles.list, classes.table),
        contentClassName: classes.content,
        dataHook: "draggable-column-multi-area",
        containerId: "multiArea",
        items: this.state.columns,
        renderItem: this.renderColumn,
        onDrop: this.handleDropColumn,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 132,
          columnNumber: 11
        }
      })));
    }
  }]);
}(React.Component);
export { MultiAreaListWithSortableColumns as default };