"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IconButtonContained = void 0;
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _icons = require("../../components/icons");
var _core = require("../../core");
var _hooks = require("../../hooks");
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 mapColorStates = {
  // Primary button
  primary: {
    background: {
      default: (0, _core.hexToRgba)(_core.IOColors["blueIO-500"], 0),
      pressed: (0, _core.hexToRgba)(_core.IOColors["blueIO-500"], 0.15),
      disabled: "transparent"
    },
    icon: {
      default: _core.IOColors["blueIO-500"],
      pressed: _core.IOColors["blueIO-600"],
      disabled: (0, _core.hexToRgba)(_core.IOColors["blueIO-500"], 0.25)
    }
  },
  // Neutral button
  neutral: {
    background: {
      default: _core.IOColors.white,
      pressed: _core.IOColors["grey-50"],
      disabled: "transparent"
    },
    icon: {
      default: _core.IOColors["grey-700"],
      pressed: _core.IOColors.black,
      disabled: _core.IOColors["grey-450"]
    }
  },
  // Contrast button
  contrast: {
    background: {
      default: (0, _core.hexToRgba)(_core.IOColors.white, 0),
      pressed: (0, _core.hexToRgba)(_core.IOColors.white, 0.2),
      disabled: "transparent"
    },
    icon: {
      default: _core.IOColors.white,
      pressed: _core.IOColors.white,
      disabled: (0, _core.hexToRgba)(_core.IOColors.white, 0.25)
    }
  }
};
const IconButtonContained = ({
  icon,
  color = "primary",
  disabled = false,
  onPress,
  accessibilityLabel,
  accessibilityHint,
  testID
}) => {
  const {
    progress,
    onPressIn,
    onPressOut,
    scaleAnimatedStyle
  } = (0, _hooks.useScaleAnimation)("exaggerated");
  const reducedMotion = (0, _reactNativeReanimated.useReducedMotion)();
  const backgroundColorAnimationStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
    backgroundColor: (0, _reactNativeReanimated.interpolateColor)(progress.value, [0, 1], [mapColorStates[color].background.default, mapColorStates[color].background.pressed])
  }));

  // Animate the <Icon> color prop
  const iconColorAnimationStyle = (0, _reactNativeReanimated.useAnimatedProps)(() => ({
    color: (0, _reactNativeReanimated.interpolateColor)(progress.value, [0, 1], [mapColorStates[color].icon.default, mapColorStates[color].icon.pressed])
  }));
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    accessibilityLabel: accessibilityLabel,
    accessibilityHint: accessibilityHint,
    accessibilityRole: "button",
    accessibilityState: {
      disabled
    },
    testID: testID,
    onPress: onPress,
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    accessible: true,
    disabled: disabled,
    style: {
      alignSelf: "flex-start"
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
      style: [_core.IOIconButtonStyles.button, _core.IOIconButtonStyles.buttonSizeDefault, !disabled && !reducedMotion && scaleAnimatedStyle, !disabled && backgroundColorAnimationStyle],
      children: !disabled ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.AnimatedIconWithColorTransition, {
        name: icon,
        animatedProps: iconColorAnimationStyle,
        color: mapColorStates[color]?.icon?.default
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.AnimatedIcon, {
        name: icon,
        color: mapColorStates[color]?.icon?.disabled
      })
    })
  });
};
exports.IconButtonContained = IconButtonContained;
//# sourceMappingURL=IconButtonContained.js.map