"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ButtonImpl = void 0;
Object.defineProperty(exports, "ButtonType", {
  enumerable: true,
  get: function () {
    return _ButtonApi.ButtonType;
  }
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _theme = require("../../contexts/theme");
var _ButtonApi = require("./Button-api");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const ButtonImpl = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
  let {
    title,
    buttonType,
    accessibilityLabel,
    testID,
    onPress,
    disabled = false,
    children
  } = _ref;
  const accessible = accessibilityLabel && accessibilityLabel !== '' ? true : false;
  const {
    Buttons,
    heavyOpacity
  } = (0, _theme.useTheme)();
  const buttonStyles = {
    [_ButtonApi.ButtonType.Critical]: {
      color: Buttons.critical,
      text: Buttons.primaryText
    },
    [_ButtonApi.ButtonType.Primary]: {
      color: Buttons.primary,
      text: Buttons.primaryText
    },
    [_ButtonApi.ButtonType.Secondary]: {
      color: Buttons.secondary,
      text: Buttons.secondaryText
    },
    [_ButtonApi.ButtonType.ModalCritical]: {
      color: Buttons.modalCritical,
      text: Buttons.primaryText
    },
    [_ButtonApi.ButtonType.ModalPrimary]: {
      color: Buttons.modalPrimary,
      text: Buttons.modalPrimaryText
    },
    [_ButtonApi.ButtonType.ModalSecondary]: {
      color: Buttons.modalSecondary,
      text: Buttons.modalSecondaryText
    }
  };
  const [isActive, setIsActive] = (0, _react.useState)(false);
  return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: onPress,
    accessible: accessible,
    accessibilityLabel: accessibilityLabel,
    accessibilityRole: 'button',
    onPressIn: () => setIsActive(!disabled && true),
    onPressOut: () => setIsActive(false),
    testID: testID,
    style: [buttonStyles[buttonType].color, disabled && (buttonType === _ButtonApi.ButtonType.Primary ? Buttons.primaryDisabled : Buttons.secondaryDisabled), isActive && buttonType === _ButtonApi.ButtonType.Secondary && {
      backgroundColor: Buttons.primary.backgroundColor
    }],
    disabled: disabled,
    activeOpacity: heavyOpacity,
    ref: ref
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flexDirection: 'row',
      justifyContent: 'center',
      alignItems: 'center'
    }
  }, children, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: [buttonStyles[buttonType].text, disabled && (buttonType === _ButtonApi.ButtonType.Primary ? Buttons.primaryTextDisabled : Buttons.secondaryTextDisabled), isActive && {
      textDecorationLine: 'underline'
    }, isActive && buttonType === _ButtonApi.ButtonType.Secondary && {
      color: Buttons.primaryText.color
    }]
  }, title)));
});
exports.ButtonImpl = ButtonImpl;
var _default = ButtonImpl;
exports.default = _default;
//# sourceMappingURL=Button.js.map