Liferay.Loader.define("data-engine-taglib@2.5.18/data_layout_builder/js/components/field-types/FieldType.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/layout', '@frontend-taglib-clay$clayui/loading-indicator', '@frontend-taglib-clay$clayui/sticker', '@frontend-taglib-clay$clayui/tooltip', 'frontend-js-react-web$classnames', 'frontend-js-react-web$react', 'frontend-js-react-web$react-dnd', 'frontend-js-react-web$react-dnd-html5-backend', '../../drag-and-drop/dragTypes.es', '../button/Button.es', '../drop-down/DropDown.es', './FieldTypeDragPreview.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 _loadingIndicator = _interopRequireDefault(require("@frontend-taglib-clay$clayui/loading-indicator"));

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

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

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

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

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

    var _reactDndHtml5Backend = require("frontend-js-react-web$react-dnd-html5-backend");

    var _dragTypes = require("../../drag-and-drop/dragTypes.es");

    var _Button = _interopRequireDefault(require("../button/Button.es"));

    var _DropDown = _interopRequireDefault(require("../drop-down/DropDown.es"));

    var _FieldTypeDragPreview = _interopRequireDefault(require("./FieldTypeDragPreview.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 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;
    }

    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 ICONS = {
      checkbox_multiple: 'select-from-list',
      document_library: 'upload',
      numeric: 'caret-double',
      radio: 'radio-button',
      select: 'list'
    };

    var _default = function _default(props) {
      var actions = props.actions,
          active = props.active,
          className = props.className,
          _props$deleteLabel = props.deleteLabel,
          deleteLabel = _props$deleteLabel === void 0 ? Liferay.Language.get('delete') : _props$deleteLabel,
          description = props.description,
          disabled = props.disabled,
          _props$dragAlignment = props.dragAlignment,
          dragAlignment = _props$dragAlignment === void 0 ? 'left' : _props$dragAlignment,
          _props$draggable = props.draggable,
          draggable = _props$draggable === void 0 ? true : _props$draggable,
          _props$dragType = props.dragType,
          dragType = _props$dragType === void 0 ? _dragTypes.DRAG_FIELD_TYPE : _props$dragType,
          icon = props.icon,
          label = props.label,
          name = props.name,
          onClick = props.onClick,
          onDelete = props.onDelete,
          onDoubleClick = props.onDoubleClick;

      var _useDrag = (0, _reactDnd.useDrag)({
        canDrag: function canDrag(_) {
          return !disabled && draggable;
        },
        collect: function collect(monitor) {
          return {
            dragging: monitor.isDragging()
          };
        },
        item: {
          data: _objectSpread({}, props),
          preview: function preview() {
            return _react["default"].createElement(_FieldTypeDragPreview["default"], props);
          },
          type: dragType
        }
      }),
          _useDrag2 = _slicedToArray(_useDrag, 3),
          dragging = _useDrag2[0].dragging,
          drag = _useDrag2[1],
          preview = _useDrag2[2];

      (0, _react.useEffect)(function () {
        preview((0, _reactDndHtml5Backend.getEmptyImage)(), {
          captureDraggingState: true
        });
      }, [preview]);

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

      var fieldIcon = ICONS[icon] ? ICONS[icon] : icon;
      return _react["default"].createElement(_layout["default"].ContentRow, {
        className: (0, _classnames["default"])(className, 'field-type', {
          active: active,
          disabled: disabled,
          dragging: dragging,
          loading: loading
        }),
        "data-field-type-name": name,
        onClick: onClick && function handleOnClick() {
          onClick(_objectSpread({}, props));
        },
        onDoubleClick: onDoubleClick && function handleOnDoubleClick() {
          if (disabled) {
            return;
          }

          onDoubleClick(_objectSpread({}, props));
        },
        ref: drag,
        verticalAlign: "center"
      }, draggable && dragAlignment === 'left' && _react["default"].createElement(_layout["default"].ContentCol, {
        className: "pl-2 pr-2"
      }, _react["default"].createElement(_icon["default"], {
        symbol: "drag"
      })), _react["default"].createElement(_layout["default"].ContentCol, {
        className: (0, _classnames["default"])('pr-2', {
          'pl-2': dragAlignment === 'right'
        })
      }, _react["default"].createElement(_sticker["default"], {
        className: "data-layout-builder-field-sticker",
        displayType: "light",
        size: "md"
      }, _react["default"].createElement(_icon["default"], {
        symbol: fieldIcon
      }))), _react["default"].createElement(_layout["default"].ContentCol, {
        className: "pr-2",
        expand: true
      }, _react["default"].createElement("h4", {
        className: "list-group-title text-truncate"
      }, _react["default"].createElement("span", null, label)), description && _react["default"].createElement("p", {
        className: "list-group-subtitle text-truncate"
      }, _react["default"].createElement("small", null, description))), _react["default"].createElement("div", {
        className: "autofit-col pr-2"
      }, actions && _react["default"].createElement(_DropDown["default"], {
        actions: actions
      })), draggable && dragAlignment === 'right' && _react["default"].createElement(_layout["default"].ContentCol, {
        className: "pr-2"
      }, _react["default"].createElement(_icon["default"], {
        symbol: "drag"
      })), onDelete && _react["default"].createElement("div", {
        className: "field-type-remove-icon"
      }, loading ? _react["default"].createElement(_loadingIndicator["default"], null) : _react["default"].createElement(_tooltip.ClayTooltipProvider, null, _react["default"].createElement(_Button["default"], {
        borderless: true,
        "data-tooltip-align": "right",
        "data-tooltip-delay": "200",
        displayType: "secondary",
        onClick: function onClick(event) {
          event.stopPropagation();
          setLoading(true);
          onDelete(name).then(function () {
            return setLoading(false);
          })["catch"](function (error) {
            setLoading(false);
            throw error;
          });
        },
        symbol: "times-circle",
        title: deleteLabel
      }))));
    };

    exports["default"] = _default;
    //# sourceMappingURL=FieldType.es.js.map
  }
});
//# sourceMappingURL=FieldType.es.js.map