import _noop from "lodash/fp/noop";
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { useMemo, useCallback } from 'react';
import map from 'lodash/fp/map';
import classnames from 'classnames';
import ButtonLink from '../button-link';
import style from './style.css';
import propTypes, { buttonPropTypes } from './types';
import { DEFAULT_ICON_STYLE, THEMES } from './utils';
const buildCustomIconByTheme = icon => {
  if (!icon) return;
  const {
    theme,
    ...iconProps
  } = icon;
  const custom = theme && THEMES[theme];
  if (!custom) return iconProps;
  const customProps = custom ? {
    ...DEFAULT_ICON_STYLE,
    faIcon: {
      ...DEFAULT_ICON_STYLE.faIcon,
      ...custom
    }
  } : null;
  return {
    ...iconProps,
    ...customProps
  };
};
const Button = props => {
  const {
    'data-name': dataName,
    disabled,
    label,
    onClick = _noop,
    type = 'default',
    buttonLinkType,
    icon,
    customStyle = {},
    ...rest
  } = props;
  const styleButton = classnames(style.button, type === 'default' && style.defaultStyle, type === 'defaultLeft' && style.defaultLeft, type === 'dangerous' && style.dangerous, type === 'dangerousLeft' && style.dangerousLeft, disabled && style.disabled);
  const handleOnClick = useCallback(() => onClick(), [onClick]);
  const buttonLinkProps = {
    ...rest,
    'aria-label': label,
    disabled,
    label,
    type: buttonLinkType,
    onClick: handleOnClick,
    'data-name': dataName,
    className: styleButton,
    customStyle: {
      ...customStyle
    }
  };
  const iconProps = buildCustomIconByTheme(icon);
  return /*#__PURE__*/React.createElement(ButtonLink, _extends({}, buttonLinkProps, {
    icon: iconProps
  }));
};
Button.propTypes = process.env.NODE_ENV !== "production" ? buttonPropTypes : {};
const ButtonMenu = props => {
  const {
    buttons,
    'data-name': dataName
  } = props;
  const buildButton = useCallback((button, index) => {
    return /*#__PURE__*/React.createElement(Button, _extends({}, button, {
      key: button.label + index
    }));
  }, []);
  const buttonList = useMemo(
  // @ts-expect-error (to avoid using map as any)
  () => map.convert({
    cap: false
  })(buildButton, buttons), [buttons, buildButton]);
  return /*#__PURE__*/React.createElement("div", {
    "data-name": dataName,
    className: style.buttonMenuContainer
  }, buttonList);
};
ButtonMenu.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
export default ButtonMenu;
//# sourceMappingURL=index.js.map