"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.Button = exports.BUTTON_SIZE = void 0;
var _reactNative = require("react-native");
var _Typography = require("../../../core/components/Typography/Typography");
var _styles = require("./styles");
var _reactNativeSvg = require("react-native-svg");
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); }
let BUTTON_SIZE = exports.BUTTON_SIZE = /*#__PURE__*/function (BUTTON_SIZE) {
  BUTTON_SIZE["SMALL"] = "small";
  BUTTON_SIZE["LARGE"] = "large";
  return BUTTON_SIZE;
}({});
const Button = ({
  icon,
  children,
  style,
  iconProps,
  size = BUTTON_SIZE.LARGE,
  type = 'primary',
  textStyle,
  disabled,
  ...props
}) => {
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const buttonStyles = type === 'inline' ? [styles[`button${capitalize(type)}`], disabled && styles[`button${capitalize(type)}Disabled`], style] : [styles.button, styles[`button${capitalize(type)}`], styles[`button${capitalize(size)}`], icon && children ? styles[`${size}WithIcon`] : null, icon && !children ? styles[`${size}OnlyIcon`] : null, disabled && styles[`button${capitalize(type)}Disabled`], style];
  const textStyles = [styles[`text${capitalize(type)}`], textStyle];
  const iconColor = {
    primary: theme.colors.background,
    secondary: theme.colors.secondary
  };
  const renderChildren = () => {
    if (!children) return null;
    if (typeof children !== 'string') return children;
    if (type === 'inline') return /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
      style: buttonStyles
    }, children);
    if (size === 'small') {
      return /*#__PURE__*/React.createElement(_Typography.Typography.CaptionBold, {
        numberOfLines: 1,
        style: textStyles
      }, children);
    }
    return /*#__PURE__*/React.createElement(_Typography.Typography.BodyBold, {
      numberOfLines: 1,
      style: textStyles
    }, children);
  };
  return /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, _extends({}, props, {
    disabled: disabled,
    style: buttonStyles,
    activeOpacity: 0.7,
    accessibilityRole: "button"
  }), icon && /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, _extends({
    xml: icon,
    width: 20,
    height: 20,
    color: iconColor[type]
  }, iconProps)), renderChildren());
};
exports.Button = Button;
const capitalize = str => {
  return str.charAt(0).toUpperCase() + str.slice(1);
};
var _default = exports.default = Button;
//# sourceMappingURL=Button.js.map