function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React from 'react';
import PropTypes from 'prop-types';
import defaultStyle from './Button.module.css';
import buttonPropTypes, { defaultProps, propsDescription } from './Button.propTypes';
import constantProps from './Button.constantProps';
import getCompliedCustomId from '../../../utils/getCompliedCustomId';
import useButtonAriaProps from './useButtonAriaProps';
import useMergeStyle from '@zohodesk/hooks/es/utils/useMergeStyle';
import buttonCssJSLogic from './Button.cssJSLogic';
export default function Button(props) {
  let {
    text,
    children,
    startIcon,
    endIcon,
    customStyle,
    customId,
    onClick,
    tagAttributes,
    tagGeneralAttributes
  } = props;
  let style = useMergeStyle(defaultStyle, customStyle);
  let hasIcon = startIcon || endIcon;
  let className = buttonCssJSLogic(props, style);
  let {
    buttonProps
  } = useButtonAriaProps(props);
  return /*#__PURE__*/React.createElement("button", _extends({}, tagGeneralAttributes, {
    className: className,
    "data-id": getCompliedCustomId(props, customId.button),
    onClick: onClick && onClick
  }, buttonProps, tagAttributes), /*#__PURE__*/React.createElement(RenderAsIcon, {
    icon: startIcon,
    className: style.start_icon
  }), text && hasIcon ? /*#__PURE__*/React.createElement("span", {
    className: style.content_text
  }, text) : text || null, !text && children ? children : null, /*#__PURE__*/React.createElement(RenderAsIcon, {
    icon: endIcon,
    className: style.end_icon
  }));
}
Button.propTypes = buttonPropTypes;
Button.defaultProps = defaultProps;
Button.propsDescription = propsDescription;
Button.constantProps = constantProps;

const RenderAsIcon = props => {
  return props.icon ? /*#__PURE__*/React.createElement("span", {
    className: props.className
  }, props.icon) : null;
};

RenderAsIcon.propTypes = {
  icon: PropTypes.any,
  className: PropTypes.string
};