"use strict";

exports.__esModule = true;
exports.default = void 0;
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireWildcard(require("react"));
var _map = _interopRequireDefault(require("lodash/fp/map"));
var _classnames = _interopRequireDefault(require("classnames"));
var _buttonLink = _interopRequireDefault(require("../button-link"));
var _style = _interopRequireDefault(require("./style.css"));
var _types = _interopRequireWildcard(require("./types"));
var _utils = require("./utils");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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); }
const buildCustomIconByTheme = icon => {
  if (!icon) return;
  const {
    theme,
    ...iconProps
  } = icon;
  const custom = theme && _utils.THEMES[theme];
  if (!custom) return iconProps;
  const customProps = custom ? {
    ..._utils.DEFAULT_ICON_STYLE,
    faIcon: {
      ..._utils.DEFAULT_ICON_STYLE.faIcon,
      ...custom
    }
  } : null;
  return {
    ...iconProps,
    ...customProps
  };
};
const Button = props => {
  const {
    'data-name': dataName,
    disabled,
    label,
    onClick = _noop2.default,
    type = 'default',
    buttonLinkType,
    icon,
    customStyle = {},
    ...rest
  } = props;
  const styleButton = (0, _classnames.default)(_style.default.button, type === 'default' && _style.default.defaultStyle, type === 'defaultLeft' && _style.default.defaultLeft, type === 'dangerous' && _style.default.dangerous, type === 'dangerousLeft' && _style.default.dangerousLeft, disabled && _style.default.disabled);
  const handleOnClick = (0, _react.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.default.createElement(_buttonLink.default, _extends({}, buttonLinkProps, {
    icon: iconProps
  }));
};
Button.propTypes = process.env.NODE_ENV !== "production" ? _types.buttonPropTypes : {};
const ButtonMenu = props => {
  const {
    buttons,
    'data-name': dataName
  } = props;
  const buildButton = (0, _react.useCallback)((button, index) => {
    return /*#__PURE__*/_react.default.createElement(Button, _extends({}, button, {
      key: button.label + index
    }));
  }, []);
  const buttonList = (0, _react.useMemo)(
  // @ts-expect-error (to avoid using map as any)
  () => _map.default.convert({
    cap: false
  })(buildButton, buttons), [buttons, buildButton]);
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": dataName,
    className: _style.default.buttonMenuContainer
  }, buttonList);
};
ButtonMenu.propTypes = process.env.NODE_ENV !== "production" ? _types.default : {};
var _default = exports.default = ButtonMenu;
//# sourceMappingURL=index.js.map