Liferay.Loader.define("dynamic-data-mapping-form-field-type@5.0.68/Select/VisibleSelectInput.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/label', 'frontend-js-react-web$classnames', 'frontend-js-react-web$react'], 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 _label = _interopRequireDefault(require("@frontend-taglib-clay$clayui/label"));

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

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

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

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * This library is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Lesser General Public License as published by the Free
     * Software Foundation; either version 2.1 of the License, or (at your option)
     * any later version.
     *
     * This library is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     * details.
     */
    var LabelOptionListItem = function LabelOptionListItem(_ref) {
      var onCloseButtonClicked = _ref.onCloseButtonClicked,
          option = _ref.option;
      return (/*#__PURE__*/_react.default.createElement("li", null, /*#__PURE__*/_react.default.createElement(_label.default, {
          className: "ddm-select-option-label",
          closeButtonProps: {
            'data-testid': "closeButton".concat(option.value),
            onClick: function onClick(event) {
              event.preventDefault();
              event.stopPropagation();
              onCloseButtonClicked({
                event: event,
                value: option.value
              });
            }
          },
          value: option.value
        }, option.label))
      );
    };

    var OptionSelected = function OptionSelected(_ref2) {
      var isPlaceholder = _ref2.isPlaceholder,
          label = _ref2.label;
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: (0, _classnames.default)('option-selected', {
            'option-selected-placeholder': isPlaceholder
          })
        }, label)
      );
    };

    var VisibleSelectInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
      var className = _ref3.className,
          id = _ref3.id,
          multiple = _ref3.multiple,
          onClick = _ref3.onClick,
          onCloseButtonClicked = _ref3.onCloseButtonClicked,
          onKeyDown = _ref3.onKeyDown,
          options = _ref3.options,
          readOnly = _ref3.readOnly,
          value = _ref3.value;
      var triggerPlaceholder = multiple ? Liferay.Language.get('choose-options') : Liferay.Language.get('choose-an-option');
      var isValueEmpty = value.length === 0;

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: (0, _classnames.default)(className, 'form-builder-select-field input-group-container'),
          onClick: onClick,
          onKeyDown: onKeyDown,
          ref: ref
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: (0, _classnames.default)('form-control results-chosen select-field-trigger', {
            disabled: readOnly,
            'multiple-label-list': multiple
          }),
          disabled: readOnly,
          id: id,
          tabIndex: "0"
        }, isValueEmpty || value.length === 1 && !multiple ? /*#__PURE__*/_react.default.createElement(OptionSelected, {
          isPlaceholder: isValueEmpty,
          label: function selectedLabel() {
            if (isValueEmpty) {
              return triggerPlaceholder;
            }

            var selectedOption = options.find(function (option) {
              return option.value === value[0];
            });
            return selectedOption ? selectedOption.label : triggerPlaceholder;
          }()
        }) : value.map(function (item) {
          var option = options.find(function (option) {
            return option.value === item;
          });
          return (/*#__PURE__*/_react.default.createElement(LabelOptionListItem, {
              key: "".concat(option.value, "-").concat(option.label),
              onCloseButtonClicked: onCloseButtonClicked,
              option: option
            })
          );
        }), /*#__PURE__*/_react.default.createElement("a", {
          className: "select-arrow-down-container"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "caret-double"
        }))))
      );
    });
    var _default = VisibleSelectInput;
    exports.default = _default;
    //# sourceMappingURL=VisibleSelectInput.es.js.map
  }
});
//# sourceMappingURL=VisibleSelectInput.es.js.map