"use strict";

import { Pressable } from "react-native";
import Animated, { interpolateColor, useAnimatedProps, useAnimatedStyle, useReducedMotion } from "react-native-reanimated";
import { AnimatedIcon, AnimatedIconWithColorTransition } from "../../components/icons";
import { IOColors, IOIconButtonStyles, hexToRgba } from "../../core";
import { useScaleAnimation } from "../../hooks";
import { jsx as _jsx } from "react/jsx-runtime";
const mapColorStates = {
  // Primary button
  primary: {
    background: {
      default: hexToRgba(IOColors["blueIO-500"], 0),
      pressed: hexToRgba(IOColors["blueIO-500"], 0.15),
      disabled: "transparent"
    },
    icon: {
      default: IOColors["blueIO-500"],
      pressed: IOColors["blueIO-600"],
      disabled: hexToRgba(IOColors["blueIO-500"], 0.25)
    }
  },
  // Neutral button
  neutral: {
    background: {
      default: IOColors.white,
      pressed: IOColors["grey-50"],
      disabled: "transparent"
    },
    icon: {
      default: IOColors["grey-700"],
      pressed: IOColors.black,
      disabled: IOColors["grey-450"]
    }
  },
  // Contrast button
  contrast: {
    background: {
      default: hexToRgba(IOColors.white, 0),
      pressed: hexToRgba(IOColors.white, 0.2),
      disabled: "transparent"
    },
    icon: {
      default: IOColors.white,
      pressed: IOColors.white,
      disabled: hexToRgba(IOColors.white, 0.25)
    }
  }
};
export const IconButtonContained = ({
  icon,
  color = "primary",
  disabled = false,
  onPress,
  accessibilityLabel,
  accessibilityHint,
  testID
}) => {
  const {
    progress,
    onPressIn,
    onPressOut,
    scaleAnimatedStyle
  } = useScaleAnimation("exaggerated");
  const reducedMotion = useReducedMotion();
  const backgroundColorAnimationStyle = useAnimatedStyle(() => ({
    backgroundColor: interpolateColor(progress.value, [0, 1], [mapColorStates[color].background.default, mapColorStates[color].background.pressed])
  }));

  // Animate the <Icon> color prop
  const iconColorAnimationStyle = useAnimatedProps(() => ({
    color: interpolateColor(progress.value, [0, 1], [mapColorStates[color].icon.default, mapColorStates[color].icon.pressed])
  }));
  return /*#__PURE__*/_jsx(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__*/_jsx(Animated.View, {
      style: [IOIconButtonStyles.button, IOIconButtonStyles.buttonSizeDefault, !disabled && !reducedMotion && scaleAnimatedStyle, !disabled && backgroundColorAnimationStyle],
      children: !disabled ? /*#__PURE__*/_jsx(AnimatedIconWithColorTransition, {
        name: icon,
        animatedProps: iconColorAnimationStyle,
        color: mapColorStates[color]?.icon?.default
      }) : /*#__PURE__*/_jsx(AnimatedIcon, {
        name: icon,
        color: mapColorStates[color]?.icon?.disabled
      })
    })
  });
};
//# sourceMappingURL=IconButtonContained.js.map