"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IconButton = void 0;
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _context = require("../../context");
var _core = require("../../core");
var _hooks = require("../../hooks");
var _icons = require("../icons");
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); }
const IconButton = ({
  color = "primary",
  persistentColorMode = false,
  icon,
  iconSize = 24,
  disabled = false,
  onPress,
  accessibilityLabel,
  accessibilityHint,
  testID
}) => {
  const theme = (0, _context.useIOTheme)();
  const {
    progress,
    onPressIn,
    onPressOut,
    scaleAnimatedStyle
  } = (0, _hooks.useScaleAnimation)("exaggerated");
  const reducedMotion = (0, _reactNativeReanimated.useReducedMotion)();
  const mapColorStates = {
    // Primary button
    primary: {
      icon: {
        default: _core.IOColors[theme["interactiveElem-default"]],
        pressed: _core.IOColors[theme["interactiveElem-pressed"]],
        disabled: _core.IOColors[theme["interactiveElem-disabled"]]
      }
    },
    // Neutral button
    neutral: {
      icon: {
        default: persistentColorMode ? _core.IOColors[_core.IOThemeLight["neutralButton-default"]] : _core.IOColors[theme["neutralButton-default"]],
        pressed: persistentColorMode ? _core.IOColors[_core.IOThemeLight["neutralButton-pressed"]] : _core.IOColors[theme["neutralButton-pressed"]],
        disabled: persistentColorMode ? _core.IOColors[_core.IOThemeLight["neutralButton-disabled"]] : _core.IOColors[theme["neutralButton-disabled"]]
      }
    },
    // Contrast button
    contrast: {
      icon: {
        default: _core.IOColors.white,
        pressed: (0, _core.hexToRgba)(_core.IOColors.white, 0.85),
        disabled: (0, _core.hexToRgba)(_core.IOColors.white, 0.25)
      }
    }
  };

  // Animate the <Icon> color prop
  const animatedColor = (0, _reactNativeReanimated.useAnimatedProps)(() => {
    const iconColor = (0, _reactNativeReanimated.interpolateColor)(progress.value, [0, 1], [mapColorStates[color].icon.default, mapColorStates[color].icon.pressed]);
    return {
      color: iconColor
    };
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    disabled: disabled
    // Events
    ,
    onPress: onPress,
    onPressIn: onPressIn,
    onPressOut: onPressOut
    // Accessibility
    ,
    accessible: true,
    accessibilityRole: "button",
    accessibilityLabel: accessibilityLabel,
    accessibilityHint: accessibilityHint,
    accessibilityState: {
      disabled
    }
    // Usability
    // Add a touchable area around the button
    ,
    hitSlop: 8
    // Test
    ,
    testID: testID,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
      style: [_core.IOIconButtonStyles.button, _core.IOIconButtonStyles.buttonSizeSmall, !disabled && !reducedMotion && scaleAnimatedStyle],
      children: !disabled ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.AnimatedIconWithColorTransition, {
        allowFontScaling: true,
        name: icon,
        size: iconSize,
        animatedProps: animatedColor,
        color: mapColorStates[color]?.icon?.default
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.AnimatedIcon, {
        allowFontScaling: true,
        name: icon,
        size: iconSize,
        color: mapColorStates[color]?.icon?.disabled
      })
    })
  });
};
exports.IconButton = IconButton;
//# sourceMappingURL=IconButton.js.map