import { _ as _defineProperty } from '../defineProperty-CEd-kZQW.js';
import { _ as _extends } from '../extends-C4cduGrv.js';
import { _ as _objectWithoutProperties } from '../objectWithoutProperties-TXwlfNxG.js';
import React__default, { useLayoutEffect } from 'react';
import cx from 'classnames';
import CKIcon from '../ck-icon/index.js';
import Portal from '../portal/index.js';
import { P as Popper } from '../Popper-CsEj9W8C.js';
import 'prop-types';
import '../ck-icon/assets/icon-map/index.js';
import '../icon/index.js';
import '@fortawesome/react-fontawesome';
import '../icon/icons.js';
import '../icon/library.js';
import '@fortawesome/fontawesome-svg-core';
import '@fortawesome/pro-solid-svg-icons';
import '@fortawesome/pro-light-svg-icons';
import '@fortawesome/free-brands-svg-icons';
import '../slicedToArray-BB-AwwkK.js';
import 'react-dom';
import '../use-rerender-once/index.js';
import '../use-force-update/index.js';
import '../usePopper-DMhEmCof.js';
import '../typeof-CgC7Bq6K.js';

var _excluded = ["active", "selected", "children"],
    _excluded2 = ["active", "popper", "children", "style"],
    _excluded3 = ["children", "className"];

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 MenuItem(_ref, ref) {
  var active = _ref.active;
      _ref.selected;
      var children = _ref.children,
      props = _objectWithoutProperties(_ref, _excluded);

  var className = cx("px-3 py-2 text-sm whitespace-no-wrap rounded leading-6", {
    "bg-gray-50 cursor-pointer": active
  });
  return /*#__PURE__*/React__default.createElement("li", _extends({
    ref: ref,
    className: className
  }, props), children);
}

MenuItem = /*#__PURE__*/React__default.forwardRef(MenuItem);
var modifiers = {
  flip: {
    enabled: true,
    behavior: ["top-start", "bottom-start"]
  }
};

function MenuListContainer(_ref2) {
  var active = _ref2.active,
      popper = _ref2.popper,
      children = _ref2.children;

  // Updates popper to ensure proper positioning when items are added/removed
  var updatePopper = function updatePopper() {
    popper.update();
  }; // Updates popper to ensure proper initial positioning when menu is opened


  useLayoutEffect(function () {
    popper.update();
  }, [active]);
  return /*#__PURE__*/React__default.createElement("div", {
    ref: popper.ref,
    onClick: updatePopper,
    style: _objectSpread(_objectSpread({}, popper.style), {}, {
      zIndex: 10000,
      paddingTop: "8px"
    })
  }, children);
}

function MenuList(_ref3, ref) {
  var active = _ref3.active;
      _ref3.popper;
      var children = _ref3.children,
      style = _ref3.style,
      props = _objectWithoutProperties(_ref3, _excluded2);

  var className = cx("bg-white p-2 shadow-lg outline-none list-none overflow-auto border border-gray-200 rounded", {
    hidden: !active
  });
  return /*#__PURE__*/React__default.createElement(Portal, null, /*#__PURE__*/React__default.createElement(Popper, {
    placement: "bottom-start",
    modifiers: modifiers
  }, function (popper) {
    return /*#__PURE__*/React__default.createElement(MenuListContainer, {
      active: active,
      popper: popper
    }, /*#__PURE__*/React__default.createElement("ul", _extends({
      ref: ref,
      style: _objectSpread({
        maxHeight: "300px",
        top: "4px"
      }, style),
      className: className
    }, props), children));
  }));
}

MenuList = /*#__PURE__*/React__default.forwardRef(MenuList);

function ToggleButton(_ref4, ref) {
  var children = _ref4.children,
      className = _ref4.className,
      props = _objectWithoutProperties(_ref4, _excluded3);

  return /*#__PURE__*/React__default.createElement("button", _extends({
    ref: ref,
    type: "button",
    className: className
  }, props), children, /*#__PURE__*/React__default.createElement(CKIcon, {
    name: "down"
  }));
}

ToggleButton = /*#__PURE__*/React__default.forwardRef(ToggleButton);

export { MenuItem, MenuList, ToggleButton };
