import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import classnames from 'classnames';
import { hyphenate } from '@bigbinary/neeto-cist';
import MenuHorizontal from '@bigbinary/neeto-icons/MenuHorizontal';
import MenuVertical from '@bigbinary/neeto-icons/MenuVertical';
import Button from '@bigbinary/neetoui/Button';
import Dropdown from '@bigbinary/neetoui/Dropdown';
import Tooltip from '@bigbinary/neetoui/Tooltip';
import { mergeRight } from 'ramda';
import { useTranslation } from 'react-i18next';
import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
import { jsx, jsxs } from 'react/jsx-runtime';
import { n } from './inject-css-C2dztUxs.js';

var MENU_ITEM_TYPES = {
  menuItem: "menuItem",
  divider: "divider"
};
var DEFAULT_TOOLTIP_PROPS = {
  disabled: true,
  position: "bottom",
  touch: ["hold", 500]
};

var _excluded$2 = ["t", "label", "key"],
  _excluded2$1 = ["isVisible", "key"];
function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var MenuItem$1 = Dropdown.MenuItem,
  Menu$1 = Dropdown.Menu;
var Submenu = withT(function (_ref) {
  var t = _ref.t,
    label = _ref.label,
    key = _ref.key,
    menuItemProps = _objectWithoutProperties(_ref, _excluded$2);
  return /*#__PURE__*/jsx(Dropdown, _objectSpread$2(_objectSpread$2({
    appendTo: "parent",
    position: "left",
    trigger: "hover",
    customTarget: /*#__PURE__*/jsx(MenuItem$1.Button, {
      "aria-haspopup": "menu",
      role: "menuitem",
      children: label
    })
  }, menuItemProps.dropdownProps), {}, {
    children: /*#__PURE__*/jsx(Menu$1, {
      "aria-label": t("neetoMolecules.moreDropdown.submenuAriaLabel", {
        label: label
      }),
      role: "menu",
      children: menuItemProps.menuItems.map(function (_ref2) {
        var _ref2$isVisible = _ref2.isVisible,
          isVisible = _ref2$isVisible === void 0 ? true : _ref2$isVisible,
          key = _ref2.key,
          menuItemProps = _objectWithoutProperties(_ref2, _excluded2$1);
        if (!isVisible) return null;
        return /*#__PURE__*/jsx(MoreDropdownMenuItem, _objectSpread$2({}, menuItemProps), key);
      })
    })
  }), key);
});

var _excluded$1 = ["onClick", "label", "type", "hasSubItems"];
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var MenuItem = Dropdown.MenuItem,
  Divider = Dropdown.Divider;
var MoreDropdownMenuItem = function MoreDropdownMenuItem(_ref) {
  var onClick = _ref.onClick,
    label = _ref.label,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? MENU_ITEM_TYPES.menuItem : _ref$type,
    _ref$hasSubItems = _ref.hasSubItems,
    hasSubItems = _ref$hasSubItems === void 0 ? false : _ref$hasSubItems,
    menuItemProps = _objectWithoutProperties(_ref, _excluded$1);
  if (type === MENU_ITEM_TYPES.divider) {
    return /*#__PURE__*/jsx(Divider, {
      role: "separator"
    });
  }
  if (hasSubItems) {
    return /*#__PURE__*/jsx(Submenu, _objectSpread$1({}, _objectSpread$1({
      label: label
    }, menuItemProps)));
  }
  return /*#__PURE__*/jsx(MenuItem.Button, _objectSpread$1(_objectSpread$1({}, _objectSpread$1({
    onClick: onClick
  }, menuItemProps)), {}, {
    role: "menuitem",
    children: label
  }));
};

var css = ".neeto-ui-btn.neeto-ui-btn--icon-only[data-dropdown-button-style=more-dropdown],.neeto-ui-btn.neeto-ui-btn--icon-only[data-testid=column-menu-button]{--neeto-ui-btn-icon-size:1.25rem;--neeto-ui-btn-padding-x:0;--neeto-ui-btn-padding-y:0;height:1.75rem;justify-content:center;width:1.75rem}.neeto-ui-btn.neeto-ui-btn--icon-only.neeto-ui-btn--size-medium[data-dropdown-button-style=more-dropdown],.neeto-ui-btn.neeto-ui-btn--icon-only.neeto-ui-btn--size-medium[data-testid=column-menu-button]{--neeto-ui-btn-icon-size:1.5rem;--neeto-ui-btn-padding-x:0;--neeto-ui-btn-padding-y:0;height:2rem;justify-content:center;width:2rem}.neeto-ui-btn.neeto-ui-btn--icon-only.neeto-ui-btn--size-large[data-dropdown-button-style=more-dropdown],.neeto-ui-btn.neeto-ui-btn--icon-only.neeto-ui-btn--size-large[data-testid=column-menu-button]{--neeto-ui-btn-icon-size:1.875rem;--neeto-ui-btn-padding-x:0;--neeto-ui-btn-padding-y:0;height:2.5rem;justify-content:center;width:2.5rem}.neeto-ui-btn.neeto-molecule-moredropdown--rounded[data-dropdown-button-style=more-dropdown]{border-radius:100%}";
n(css,{});

var _excluded = ["isRounded"],
  _excluded2 = ["isVisible", "key"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Menu = Dropdown.Menu;
var MoreDropdown = function MoreDropdown(_ref) {
  var _ref$dropdownButtonPr = _ref.dropdownButtonProps,
    dropdownButtonProps = _ref$dropdownButtonPr === void 0 ? {} : _ref$dropdownButtonPr,
    _ref$isVertical = _ref.isVertical,
    isVertical = _ref$isVertical === void 0 ? false : _ref$isVertical,
    _ref$isDisabled = _ref.isDisabled,
    isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
    _ref$dropdownProps = _ref.dropdownProps,
    dropdownProps = _ref$dropdownProps === void 0 ? {} : _ref$dropdownProps,
    menuTopChildren = _ref.menuTopChildren,
    menuBottomChildren = _ref.menuBottomChildren,
    _ref$menuItems = _ref.menuItems,
    menuItems = _ref$menuItems === void 0 ? [] : _ref$menuItems;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var isRoundedButton = dropdownButtonProps.isRounded,
    buttonProps = _objectWithoutProperties(dropdownButtonProps, _excluded);
  var tooltipProps = mergeRight(DEFAULT_TOOLTIP_PROPS, dropdownButtonProps.tooltipProps);
  var targetIcon = isVertical ? MenuVertical : MenuHorizontal;
  var isDropdownDisabled = isDisabled || dropdownProps.disabled;
  if (isDropdownDisabled && !tooltipProps.disabled) {
    return /*#__PURE__*/jsx(Tooltip, _objectSpread(_objectSpread({}, tooltipProps), {}, {
      children: /*#__PURE__*/jsx("span", {
        children: /*#__PURE__*/jsx(Button, _objectSpread({
          disabled: true,
          "data-dropdown-button-style": "more-dropdown",
          "data-testid": "more-dropdown-button",
          icon: targetIcon,
          iconPosition: "right",
          size: "medium",
          style: "text",
          className: classnames({
            "neeto-molecule-moredropdown--rounded": isRoundedButton
          })
        }, buttonProps))
      })
    }));
  }
  return /*#__PURE__*/jsx(Dropdown, _objectSpread(_objectSpread({
    className: "flex",
    disabled: isDisabled,
    icon: targetIcon,
    zIndex: 99999,
    buttonProps: _objectSpread({
      "data-dropdown-button-style": "more-dropdown",
      className: classnames("min-h-0 flex-shrink-0 neeto-molecule-moredropdown-btn", {
        "neeto-molecule-moredropdown--rounded": isRoundedButton
      }),
      style: "text",
      tooltipProps: {
        content: t("neetoMolecules.moreDropdown.tooltip"),
        position: "top",
        touch: ["hold", 500]
      },
      "aria-haspopup": "menu",
      "aria-label": t("neetoMolecules.moreDropdown.buttonAriaLabel")
    }, buttonProps)
  }, dropdownProps), {}, {
    children: /*#__PURE__*/jsxs(Menu, {
      "aria-label": t("neetoMolecules.moreDropdown.menuAriaLabel"),
      role: "menu",
      children: [menuTopChildren, menuItems.map(function (_ref2) {
        var _ref2$isVisible = _ref2.isVisible,
          isVisible = _ref2$isVisible === void 0 ? true : _ref2$isVisible,
          key = _ref2.key,
          menuItemProps = _objectWithoutProperties(_ref2, _excluded2);
        if (!isVisible) return null;
        return /*#__PURE__*/jsx(MoreDropdownMenuItem, _objectSpread({}, menuItemProps), key !== null && key !== void 0 ? key : hyphenate(menuItemProps.label));
      }), menuBottomChildren]
    })
  }));
};

export { MoreDropdown as default };
//# sourceMappingURL=MoreDropdown.js.map
