'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var base = require('./variations/_view/base.js');
var base$1 = require('./variations/_size/base.js');
var Dropdown_styles = require('./Dropdown.styles.js');
var index = require('./utils/index.js');
var react = require('../../../../utils/react.js');
var useForkRef = require('../../../../hooks/useForkRef.js');
var useFocusTrap = require('../../../../hooks/useFocusTrap.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["id", "target", "children", "hasArrow", "role", "view", "size", "frame", "onToggle", "isFocusTrapped", "isOpen", "opened", "placement", "trigger", "offset", "preventOverflow", "closeOnOverlayClick", "closeOnEsc"];
/**
 * Выпадающий список без внешнего контроля видимости.
 */
var dropdownOldRoot = function dropdownOldRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (_ref, outerRootRef) {
    var id = _ref.id,
      target = _ref.target,
      children = _ref.children,
      hasArrow = _ref.hasArrow,
      role = _ref.role,
      view = _ref.view,
      size = _ref.size,
      frame = _ref.frame,
      _onToggle = _ref.onToggle,
      _ref$isFocusTrapped = _ref.isFocusTrapped,
      isFocusTrapped = _ref$isFocusTrapped === void 0 ? true : _ref$isFocusTrapped,
      _ref$isOpen = _ref.isOpen,
      isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen,
      _ref$opened = _ref.opened,
      opened = _ref$opened === void 0 ? false : _ref$opened,
      _ref$placement = _ref.placement,
      placement = _ref$placement === void 0 ? 'auto' : _ref$placement,
      _ref$trigger = _ref.trigger,
      trigger = _ref$trigger === void 0 ? 'click' : _ref$trigger,
      _ref$offset = _ref.offset,
      offset = _ref$offset === void 0 ? [0, 6] : _ref$offset,
      _ref$preventOverflow = _ref.preventOverflow,
      preventOverflow = _ref$preventOverflow === void 0 ? false : _ref$preventOverflow,
      _ref$closeOnOverlayCl = _ref.closeOnOverlayClick,
      closeOnOverlayClick = _ref$closeOnOverlayCl === void 0 ? false : _ref$closeOnOverlayCl,
      _ref$closeOnEsc = _ref.closeOnEsc,
      closeOnEsc = _ref$closeOnEsc === void 0 ? false : _ref$closeOnEsc,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
    var innerIsOpen = Boolean(isOpen || opened);
    var uniqId = react.safeUseId();
    var innerId = id || uniqId;
    var rootRef = React.useRef(null);
    var dropdownRef = React.useRef(null);
    var handleRef = useForkRef.useForkRef(rootRef, outerRootRef);
    var trapRef = useFocusTrap.useFocusTrap(innerIsOpen && isFocusTrapped);
    var dropdownForkRef = useForkRef.useForkRef(dropdownRef, trapRef);
    return /*#__PURE__*/React__default.default.createElement(Dropdown_styles.StyledPopover, {
      role: role,
      opened: innerIsOpen,
      usePortal: false,
      onToggle: function onToggle(is, event) {
        return _onToggle === null || _onToggle === void 0 ? void 0 : _onToggle(is, event);
      },
      id: innerId,
      ref: dropdownForkRef,
      target: target,
      offset: offset,
      preventOverflow: preventOverflow,
      hasArrow: hasArrow,
      placement: index.getPlacements(placement),
      trigger: trigger,
      closeOnOverlayClick: closeOnOverlayClick,
      closeOnEsc: closeOnEsc,
      isFocusTrapped: isFocusTrapped,
      frame: frame
    }, /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      ref: handleRef,
      view: view,
      size: size
    }, rest), /*#__PURE__*/React__default.default.createElement(Dropdown_styles.StyledDropdown, null, children)));
  });
};
var dropdownOldConfig = {
  name: 'Dropdown',
  tag: 'div',
  layout: dropdownOldRoot,
  base: '',
  variations: {
    view: {
      css: base.base
    },
    size: {
      css: base$1.base
    }
  },
  defaults: {
    view: 'default',
    size: 'm'
  }
};

exports.dropdownOldConfig = dropdownOldConfig;
exports.dropdownOldRoot = dropdownOldRoot;
//# sourceMappingURL=DropdownOld.js.map
