"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DraggableBodyRows = void 0;
var _react = _interopRequireDefault(require("react"));
var _eui = require("@elastic/eui");
var _body_rows = require("./body_rows");
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

const DraggableBodyRows = ({
  items,
  onReorder,
  renderItem
}) => {
  return /*#__PURE__*/_react.default.createElement(_eui.EuiDragDropContext, {
    onDragEnd: ({
      source,
      destination
    }) => {
      if (source && destination) {
        const reorderedItems = (0, _eui.euiDragDropReorder)(items, source.index, destination === null || destination === void 0 ? void 0 : destination.index);
        onReorder(reorderedItems, items);
      }
    }
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiDroppable, {
    droppableId: "ReorderingArea",
    grow: false
  }, /*#__PURE__*/_react.default.createElement(_body_rows.BodyRows, {
    items: items,
    renderItem: renderItem
  })));
};
exports.DraggableBodyRows = DraggableBodyRows;