'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var neetoAtoms = require('@bigbinary/neeto-atoms');
var classnames = require('classnames');
var neetoCist = require('@bigbinary/neeto-cist');
var ramda = require('ramda');
var reactI18next = require('react-i18next');
var reactUtils = require('@bigbinary/neeto-commons-frontend/v2/react-utils');
var jsxRuntime = require('react/jsx-runtime');
var createLucideIcon = require('../createLucideIcon-DBDhE7kE.js');
var ellipsis = require('../ellipsis-BcfLTtl5.js');
require('react');

/**
 * @license lucide-react v1.7.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */


const __iconNode = [
  ["circle", { cx: "12", cy: "12", r: "1", key: "41hilf" }],
  ["circle", { cx: "12", cy: "5", r: "1", key: "gxeob9" }],
  ["circle", { cx: "12", cy: "19", r: "1", key: "lyex9k" }]
];
const EllipsisVertical = createLucideIcon.createLucideIcon("ellipsis-vertical", __iconNode);

var DEFAULT_TOOLTIP_PROPS = {
  disabled: true,
  position: "bottom"
};

var _excluded$2 = ["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 Submenu = reactUtils.withT(function (_ref) {
  var t = _ref.t,
    label = _ref.label,
    _ref$menuItems = _ref.menuItems,
    menuItems = _ref$menuItems === void 0 ? [] : _ref$menuItems;
  return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.DropdownMenu.SubMenu, {
    label: label,
    triggerProps: {
      "aria-haspopup": "menu"
    },
    contentProps: {
      "aria-label": t("neetoMolecules.moreDropdown.submenuAriaLabel", {
        label: label
      })
    },
    children: menuItems.map(function (_ref2) {
      var _ref2$isVisible = _ref2.isVisible,
        isVisible = _ref2$isVisible === void 0 ? true : _ref2$isVisible,
        key = _ref2.key,
        itemProps = _objectWithoutProperties(_ref2, _excluded$2);
      if (!isVisible) return null;
      return /*#__PURE__*/jsxRuntime.jsx(MenuItem, _objectSpread$2({}, itemProps), key !== null && key !== void 0 ? key : neetoCist.hyphenate(itemProps.label || "menu-item"));
    })
  });
});

var _excluded$1 = ["onClick", "label", "type", "hasSubItems", "menuItems", "dropdownProps"];
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 = function MenuItem(_ref) {
  var onClick = _ref.onClick,
    label = _ref.label,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? "menuItem" : _ref$type,
    _ref$hasSubItems = _ref.hasSubItems,
    hasSubItems = _ref$hasSubItems === void 0 ? false : _ref$hasSubItems,
    menuItems = _ref.menuItems,
    dropdownProps = _ref.dropdownProps,
    menuItemProps = _objectWithoutProperties(_ref, _excluded$1);
  if (type === "divider") return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.DropdownMenu.Divider, {
    role: "separator"
  });
  if (hasSubItems) {
    return /*#__PURE__*/jsxRuntime.jsx(Submenu, _objectSpread$1({}, _objectSpread$1({
      dropdownProps: dropdownProps,
      label: label,
      menuItems: menuItems
    }, menuItemProps)));
  }
  return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.DropdownMenu.MenuItem, _objectSpread$1(_objectSpread$1({
    onClick: onClick,
    role: "menuitem"
  }, menuItemProps), {}, {
    children: label
  }));
};

var _excluded = ["isRounded", "size", "tooltipProps", "variant"],
  _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 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 = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var isRoundedButton = dropdownButtonProps.isRounded,
    _dropdownButtonProps$ = dropdownButtonProps.size,
    buttonSize = _dropdownButtonProps$ === void 0 ? "icon" : _dropdownButtonProps$,
    customTooltipProps = dropdownButtonProps.tooltipProps,
    _dropdownButtonProps$2 = dropdownButtonProps.variant,
    variant = _dropdownButtonProps$2 === void 0 ? "ghost" : _dropdownButtonProps$2,
    buttonProps = _objectWithoutProperties(dropdownButtonProps, _excluded);
  var tooltipProps = ramda.mergeRight(DEFAULT_TOOLTIP_PROPS, customTooltipProps);
  var TargetIcon = isVertical ? EllipsisVertical : ellipsis.Ellipsis;
  var isDropdownDisabled = isDisabled || dropdownProps.disabled;
  var triggerClassName = classnames("shrink-0", {
    "rounded-full": isRoundedButton
  });
  if (isDropdownDisabled && !tooltipProps.disabled) {
    return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Tooltip, {
      content: tooltipProps.content,
      position: tooltipProps.position || "bottom",
      children: /*#__PURE__*/jsxRuntime.jsx("span", {
        children: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, _objectSpread({
          variant: variant,
          disabled: true,
          className: triggerClassName,
          "data-dropdown-button-style": "more-dropdown",
          "data-testid": "more-dropdown-button",
          icon: TargetIcon,
          size: buttonSize
        }, buttonProps))
      })
    });
  }
  return /*#__PURE__*/jsxRuntime.jsxs(neetoAtoms.DropdownMenu, _objectSpread(_objectSpread({
    customTarget: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, _objectSpread({
      variant: variant,
      "aria-haspopup": "menu",
      "aria-label": t("neetoMolecules.moreDropdown.buttonAriaLabel"),
      className: triggerClassName,
      "data-dropdown-button-style": "more-dropdown",
      disabled: isDropdownDisabled,
      icon: TargetIcon,
      size: buttonSize
    }, buttonProps)),
    dropdownProps: {
      "aria-label": t("neetoMolecules.moreDropdown.menuAriaLabel")
    }
  }, dropdownProps), {}, {
    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__*/jsxRuntime.jsx(MenuItem, _objectSpread({}, menuItemProps), key !== null && key !== void 0 ? key : neetoCist.hyphenate(menuItemProps.label || "menu-item"));
    }), menuBottomChildren]
  }));
};

module.exports = MoreDropdown;
//# sourceMappingURL=MoreDropdown.js.map
