"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.numberButtonStyles = exports.NumberButton = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeHapticFeedback = _interopRequireDefault(require("react-native-haptic-feedback"));
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _context = require("../../context");
var _core = require("../../core");
var _hooks = require("../../hooks");
var _typography = require("../typography");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const numberPadBtnSize = 56;

/**
 * Based on a `Pressable` element, it displays a number button with animations on press In and Out.
 *
 * @returns {JSX.Element} The rendered `NumberButton`
 */
const NumberButton = exports.NumberButton = /*#__PURE__*/(0, _react.memo)(({
  number,
  variant,
  onPress
}) => {
  const theme = (0, _context.useIOTheme)();
  const {
    progress,
    onPressIn,
    onPressOut,
    scaleAnimatedStyle
  } = (0, _hooks.useScaleAnimation)("medium");
  const reducedMotion = (0, _reactNativeReanimated.useReducedMotion)();
  const colorMap = (0, _react.useMemo)(() => ({
    neutral: {
      background: (0, _core.hexToRgba)(_core.IOColors[theme["interactiveElem-default"]], 0.1),
      pressed: (0, _core.hexToRgba)(_core.IOColors[theme["interactiveElem-default"]], 0.35),
      foreground: theme["interactiveElem-default"]
    },
    primary: {
      background: (0, _core.hexToRgba)(_core.IOColors.white, 0.15),
      pressed: (0, _core.hexToRgba)(_core.IOColors.white, 0.5),
      foreground: "white"
    }
  }), [theme]);

  // Interpolate animation values from `isPressed` values
  const pressedAnimationStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
    backgroundColor: (0, _reactNativeReanimated.interpolateColor)(progress.value, [0, 1], [colorMap[variant].background, colorMap[variant].pressed])
  }));
  const handleOnPress = (0, _react.useCallback)(() => {
    _reactNativeHapticFeedback.default.trigger("impactLight");
    onPress(number);
  }, [number, onPress]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    accessible: true,
    accessibilityRole: "button",
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    onPress: handleOnPress,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
      style: [numberButtonStyles.circularButton, numberButtonStyles.buttonSize, pressedAnimationStyle, !reducedMotion && scaleAnimatedStyle],
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.IOText, {
        size: 22,
        weight: "Semibold",
        color: colorMap[variant].foreground,
        style: {
          // Additional prop for Android
          textAlignVertical: "center"
        },
        children: number
      })
    })
  });
});
const numberButtonStyles = exports.numberButtonStyles = _reactNative.StyleSheet.create({
  circularButton: {
    alignItems: "center",
    justifyContent: "center",
    borderRadius: numberPadBtnSize / 2
  },
  buttonSize: {
    width: numberPadBtnSize,
    height: numberPadBtnSize
  }
});
//# sourceMappingURL=NumberButton.js.map