"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.TokenInputMenu = void 0;var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _react = _interopRequireDefault(require("react"));


var _ThemeFactory = require("../../lib/theming/ThemeFactory");

var _Popup = require("../../internal/Popup");

var _CustomComboBox = require("../../internal/CustomComboBox");


var _ThemeContext = require("../../lib/theming/ThemeContext");



var _TokenInput = require("./TokenInput");var





















TokenInputMenu = exports.TokenInputMenu = /*#__PURE__*/function (_React$Component) {function TokenInputMenu() {var _this;for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;_this.



    state = {};_this.



    menu = null;_this.
























    getMenuRef = function () {return _this.menu;};_this.









































































    handleMenuPositionChange = function (_, isFullyVisible) {
      if (!_this.state.forceMenuLeftAlign && !isFullyVisible && _this.props.menuAlign === 'cursor') {
        _this.setState({ forceMenuLeftAlign: true });
      }
    };_this.

    getPopupMargin = function () {
      var paddingY = parseInt(_this.theme.tokenInputPaddingYSmall, 10) || 0;
      var outlineWidth = parseInt(_this.theme.controlOutlineWidth, 10) || 0;
      var marginY = parseInt(_this.theme.tokenMarginYSmall, 10) || 0;

      return paddingY + outlineWidth + marginY;
    };_this.

    menuRef = function (node) {return _this.menu = node;};return _this;}(0, _inheritsLoose2.default)(TokenInputMenu, _React$Component);var _proto = TokenInputMenu.prototype;_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Provider, { value: _ThemeFactory.ThemeFactory.create({ popupMargin: _this2.getPopupMargin() + 'px', popupBackground: _this2.theme.tokenInputMenuPopupBg }, theme) }, _this2.renderMain());});};_proto.getPopupMarginSize = function getPopupMarginSize(t) {switch (this.props.size) {case 'large':return t.tokenInputPopupMarginLarge;case 'medium':return t.tokenInputPopupMarginMedium;case 'small':default:return t.tokenInputPopupMarginSmall;}};_proto.renderMain = function renderMain() {var _this$props = this.props,loading = _this$props.loading,maxMenuHeight = _this$props.maxMenuHeight,renderTotalCount = _this$props.renderTotalCount,totalCount = _this$props.totalCount,opened = _this$props.opened,items = _this$props.items,renderNotFound = _this$props.renderNotFound,renderItem = _this$props.renderItem,onValueChange = _this$props.onValueChange,renderAddButton = _this$props.renderAddButton,anchorElementForCursor = _this$props.anchorElementForCursor,anchorElementRoot = _this$props.anchorElementRoot,menuWidth = _this$props.menuWidth;var menuAlign = this.state.forceMenuLeftAlign ? 'left' : this.props.menuAlign;return /*#__PURE__*/_react.default.createElement(_Popup.Popup, { id: this.props.popupMenuId, "data-tid": _TokenInput.TokenInputDataTids.tokenInputMenu, opened: !!opened, positions: menuAlign === 'cursor' ? ['bottom left', 'top left'] : ['bottom left', 'top left', 'bottom right', 'top right'], anchorElement: menuAlign === 'cursor' ? anchorElementForCursor : anchorElementRoot, popupOffset: menuAlign === 'left' ? parseInt(this.theme.tokenInputPopupOffset) : 8 + parseInt(this.theme.tokenInputPopupOffset), margin: menuAlign === 'left' ? 1 : parseInt(this.getPopupMarginSize(this.theme)), hasShadow: true, width: menuAlign === 'cursor' ? 'auto' : menuWidth, withoutMobile: true, onPositionChange: this.handleMenuPositionChange }, /*#__PURE__*/_react.default.createElement(_CustomComboBox.ComboBoxMenu, { size: this.props.size, items: items, loading: loading, hasMargin: false, maxMenuHeight: maxMenuHeight, onValueChange: onValueChange, opened: opened, refMenu: this.menuRef, renderTotalCount: renderTotalCount, renderItem: renderItem, renderNotFound: renderNotFound, totalCount: totalCount, renderAddButton: renderAddButton }));};return TokenInputMenu;}(_react.default.Component);TokenInputMenu.__KONTUR_REACT_UI__ = 'TokenInputMenu';TokenInputMenu.displayName = 'TokenInputMenu';