Liferay.Loader.define("app-builder-web@1.0.76/js/pages/table-view/DropZone.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/layout', '@frontend-taglib-clay$clayui/tooltip', 'frontend-js-react-web$classnames', 'data-engine-taglib', 'frontend-js-react-web$react', 'frontend-js-react-web$react-dnd', '../../components/table/Table.es', './ColumnOverlay.es', './DropZonePlaceholder.es', './EditTableViewContext.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

    var _layout = _interopRequireDefault(require("@frontend-taglib-clay$clayui/layout"));

    var _tooltip = require("@frontend-taglib-clay$clayui/tooltip");

    var _classnames = _interopRequireDefault(require("frontend-js-react-web$classnames"));

    var _dataEngineTaglib = require("data-engine-taglib");

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _reactDnd = require("frontend-js-react-web$react-dnd");

    var _Table = _interopRequireDefault(require("../../components/table/Table.es"));

    var _ColumnOverlay = _interopRequireDefault(require("./ColumnOverlay.es"));

    var _DropZonePlaceholder = _interopRequireDefault(require("./DropZonePlaceholder.es"));

    var _EditTableViewContext = _interopRequireDefault(require("./EditTableViewContext.es"));

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var generateItem = function generateItem(columns) {
      return columns.reduce(function (acc, column) {
        return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, column, "-"));
      }, {});
    };

    var generateItems = function generateItems(columns) {
      var rows = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
      var items = [];

      for (var i = 0; i < rows; i++) {
        items.push(generateItem(columns, i));
      }

      return items;
    };

    var DropZone = function DropZone(_ref) {
      var fields = _ref.fields,
          onAddFieldName = _ref.onAddFieldName,
          onRemoveFieldName = _ref.onRemoveFieldName;

      var _useDrop = (0, _reactDnd.useDrop)({
        accept: _dataEngineTaglib.DragTypes.DRAG_FIELD_TYPE,
        collect: function collect(monitor) {
          return {
            canDrop: monitor.canDrop(),
            overTarget: monitor.isOver()
          };
        },
        drop: function drop(_ref2) {
          var name = _ref2.data.name;
          onAddFieldName(name);
        }
      }),
          _useDrop2 = _slicedToArray(_useDrop, 2),
          _useDrop2$ = _useDrop2[0],
          canDrop = _useDrop2$.canDrop,
          overTarget = _useDrop2$.overTarget,
          drop = _useDrop2[1];

      var _useState = (0, _react.useState)(),
          _useState2 = _slicedToArray(_useState, 2),
          container = _useState2[0],
          setContainer = _useState2[1];

      var containerRef = (0, _react.useRef)();
      var empty = fields.length === 0;
      (0, _react.useLayoutEffect)(function () {
        if (containerRef.current) {
          setContainer(containerRef.current);
        }
      }, [empty]);

      var _useContext = (0, _react.useContext)(_EditTableViewContext.default),
          _useContext2 = _slicedToArray(_useContext, 1),
          _useContext2$ = _useContext2[0],
          defaultLanguageId = _useContext2$.dataDefinition.defaultLanguageId,
          appliedFilters = _useContext2$.dataListView.appliedFilters,
          editingLanguageId = _useContext2$.editingLanguageId;

      if (empty) {
        return (/*#__PURE__*/_react.default.createElement(_layout.default.Sheet, {
            className: "p-4"
          }, /*#__PURE__*/_react.default.createElement("div", {
            className: "empty-drop-zone-header"
          }), /*#__PURE__*/_react.default.createElement("div", {
            className: (0, _classnames.default)('empty-drop-zone', {
              'target-droppable': canDrop,
              'target-over': overTarget
            }),
            ref: drop
          }, /*#__PURE__*/_react.default.createElement("p", {
            className: "m-0"
          }, Liferay.Language.get('drag-columns-from-the-sidebar-and-drop-here'))))
        );
      }

      var getLocalizableValue = function getLocalizableValue(label) {
        return label[editingLanguageId] || label[defaultLanguageId];
      };

      return (/*#__PURE__*/_react.default.createElement("div", {
          ref: containerRef
        }, /*#__PURE__*/_react.default.createElement(_Table.default, {
          actions: [],
          checkable: true,
          columns: fields.map(function (_ref3) {
            var label = _ref3.label,
                name = _ref3.name;
            return {
              key: label,
              value: /*#__PURE__*/_react.default.createElement(_layout.default.ContainerFluid, {
                className: "p-0"
              }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentRow, {
                verticalAlign: "center"
              }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, {
                expand: true
              }, getLocalizableValue(label)), Object.prototype.hasOwnProperty.call(appliedFilters, name) && /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, null, /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
                "data-tooltip-align": "top",
                "data-tooltip-delay": "200",
                symbol: "filter",
                title: Liferay.Language.get('this-column-has-applied-filters')
              })))))
            };
          }),
          items: generateItems(fields.map(function (_ref4) {
            var label = _ref4.label;
            return getLocalizableValue(label);
          })),
          ref: drop
        }), container && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_DropZonePlaceholder.default, {
          container: container,
          fields: fields,
          onAddFieldName: onAddFieldName
        }), /*#__PURE__*/_react.default.createElement(_ColumnOverlay.default, {
          container: container,
          fields: fields,
          onRemoveFieldName: onRemoveFieldName
        })))
      );
    };

    var _default = DropZone;
    exports.default = _default;
    //# sourceMappingURL=DropZone.es.js.map
  }
});
//# sourceMappingURL=DropZone.es.js.map