Liferay.Loader.define("depot-web@1.0.90/js/LanguageListItemEditable.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/drop-down', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/label', '@frontend-taglib-clay$clayui/layout', '@frontend-taglib-clay$clayui/table', 'frontend-js-react-web$classnames', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', 'frontend-js-react-web$react-dnd'], 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 _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

    var _dropDown = _interopRequireDefault(require("@frontend-taglib-clay$clayui/drop-down"));

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

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

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

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

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

    var _propTypes = _interopRequireDefault(require("frontend-js-react-web$prop-types"));

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

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

    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;
    }

    var DROP_ZONES = {
      BOTTOM: 'BOTTOM',
      TOP: 'TOP'
    };
    var ACCEPTING_TYPES = {
      ITEM: 'ITEM'
    };
    var ITEM_HOVER_BORDER_LIMIT = 28;

    var isValidTarget = function isValidTarget(source, target, dropZone) {
      return !!(source.id !== target.id && (dropZone === DROP_ZONES.TOP && (target.index < source.index || target.index > source.index + 1) || dropZone === DROP_ZONES.BOTTOM && (target.index > source.index || target.index < source.index - 1)));
    };

    var getDropZone = function getDropZone(ref, monitor) {
      if (!ref.current) {
        return;
      }

      var clientOffset = monitor.getClientOffset();
      var dropItemBoundingRect = ref.current.getBoundingClientRect();

      var hoverClientY = clientOffset.y - dropItemBoundingRect.top;
      var dropZone = DROP_ZONES.BOTTOM;

      if (hoverClientY < ITEM_HOVER_BORDER_LIMIT) {
        dropZone = DROP_ZONES.TOP;
      }

      return dropZone;
    };

    var noop = function noop() {};

    var LanguageListItem = function LanguageListItem(_ref) {
      var displayName = _ref.displayName,
          isDefault = _ref.isDefault,
          localeId = _ref.localeId,
          onMakeDefault = _ref.onMakeDefault,
          _ref$isFirst = _ref.isFirst,
          isFirst = _ref$isFirst === void 0 ? false : _ref$isFirst,
          _ref$isLast = _ref.isLast,
          isLast = _ref$isLast === void 0 ? false : _ref$isLast,
          index = _ref.index,
          _ref$onItemDrop = _ref.onItemDrop,
          onItemDrop = _ref$onItemDrop === void 0 ? noop : _ref$onItemDrop,
          _ref$onMoveUp = _ref.onMoveUp,
          onMoveUp = _ref$onMoveUp === void 0 ? noop : _ref$onMoveUp,
          _ref$onMoveDown = _ref.onMoveDown,
          onMoveDown = _ref$onMoveDown === void 0 ? noop : _ref$onMoveDown;

      var _useState = (0, _react.useState)(false),
          _useState2 = _slicedToArray(_useState, 2),
          active = _useState2[0],
          setActive = _useState2[1];

      var _useState3 = (0, _react.useState)(),
          _useState4 = _slicedToArray(_useState3, 2),
          dropZone = _useState4[0],
          setDropZone = _useState4[1];

      var itemRef = (0, _react.useRef)();

      var _useDrag = (0, _reactDnd.useDrag)({
        collect: function collect(monitor) {
          return {
            isDragging: !!monitor.isDragging()
          };
        },
        item: {
          id: localeId,
          index: index,
          type: ACCEPTING_TYPES.ITEM
        }
      }),
          _useDrag2 = _slicedToArray(_useDrag, 2),
          isDragging = _useDrag2[0].isDragging,
          drag = _useDrag2[1];

      var _useDrop = (0, _reactDnd.useDrop)({
        accept: ACCEPTING_TYPES.ITEM,
        canDrop: function canDrop(source, monitor) {
          var dropZone = getDropZone(itemRef, monitor);
          return isValidTarget(source, {
            id: localeId,
            index: index
          }, dropZone);
        },
        collect: function collect(monitor) {
          return {
            isOver: !!monitor.isOver()
          };
        },
        drop: function drop(source, monitor) {
          if (monitor.canDrop()) {
            var newIndex = index;

            if (dropZone === DROP_ZONES.BOTTOM) {
              newIndex = index + 1;
            }

            if (newIndex > source.index) {
              newIndex = newIndex - 1;
            }

            onItemDrop(source.index, newIndex);
          }
        },
        hover: function hover(source, monitor) {
          var dropZone;

          if (isOver && monitor.canDrop()) {
            dropZone = getDropZone(itemRef, monitor);
          }

          setDropZone(dropZone);
        }
      }),
          _useDrop2 = _slicedToArray(_useDrop, 2),
          isOver = _useDrop2[0].isOver,
          drop = _useDrop2[1];

      (0, _react.useEffect)(function () {
        drag(drop(itemRef));
      }, [drag, drop]);

      return (/*#__PURE__*/_react.default.createElement(_table.default.Row, {
          className: (0, _classnames.default)('language-list-item', {
            dragging: isDragging,
            'drop-bottom': isOver && dropZone === DROP_ZONES.BOTTOM,
            'drop-top': isOver && dropZone === DROP_ZONES.TOP
          }),
          ref: itemRef
        }, /*#__PURE__*/_react.default.createElement(_table.default.Cell, {
          expanded: true
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentRow, {
          verticalAlign: "center"
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, {
          className: "autofit-padded-no-gutters"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "language-drag-handler"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "drag"
        }))), /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, {
          className: "align-items-center autofit-padded-no-gutters flex-row justify-content-start",
          expand: true
        }, displayName, isDefault && /*#__PURE__*/_react.default.createElement(_label.default, {
          className: "ml-3",
          displayType: "info"
        }, Liferay.Language.get('default'))))), /*#__PURE__*/_react.default.createElement(_table.default.Cell, {
          align: "right"
        }, /*#__PURE__*/_react.default.createElement(_dropDown.default, {
          active: active,
          onActiveChange: setActive,
          trigger: /*#__PURE__*/_react.default.createElement(_button.default, {
            borderless: true,
            displayType: "secondary",
            monospaced: true,
            small: true
          }, /*#__PURE__*/_react.default.createElement(_icon.default, {
            symbol: "ellipsis-v"
          }))
        }, /*#__PURE__*/_react.default.createElement(_dropDown.default.ItemList, null, /*#__PURE__*/_react.default.createElement(_dropDown.default.Item, {
          "data-value": localeId,
          key: localeId,
          onClick: function makeDefault(event) {
            setActive(false);
            onMakeDefault({
              localeId: localeId
            });
            Liferay.fire('inputLocalized:defaultLocaleChanged', {
              item: event.currentTarget
            });
          }
        }, Liferay.Language.get('make-default')), !isFirst && /*#__PURE__*/_react.default.createElement(_dropDown.default.Item, {
          onClick: function moveUp() {
            setActive(false);
            onMoveUp();
          }
        }, Liferay.Language.get('move-up')), !isLast && /*#__PURE__*/_react.default.createElement(_dropDown.default.Item, {
          onClick: function moveDown() {
            setActive(false);
            onMoveDown();
          }
        }, Liferay.Language.get('move-down'))))))
      );
    };

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