import { boxStyleFunctions } from "../../theme/src/style-functions";
import defaultRNStyles from "../../theme/utils/default-rn-styles";
import { getKeys } from "../../theme/utils/type-helpers";
import { removeUndefined } from "../../theme/utils/utils";
import { useStateWithStyleProps } from "../useStateWithStyleProps";

/**
 * Hook to manage a pressed state and compose extra styling while a component is pressed
 *
 * @param props - The props of the component
 * @param stateKey - The key of the state to manage
 * @param currentState - The current state of the component
 * @param styleFunctions - The style functions to use
 * @param activeComponentType - The active component type
 * @param animateable - Whether the component is animateable
 * @returns The final props of the component
 */
export const useDynamicStateStyle = (props, stateKey, currentState, styleFunctions = boxStyleFunctions, activeComponentType = "basic", animateable = true) => {
  // Override the pressed state if the parentStateValue is provided
  let stateStyles = useStateWithStyleProps(props[stateKey], styleFunctions);

  // If there are no state styles, return the original props
  if (!stateStyles) return props;
  delete props[stateKey];
  let finalProps = props;

  // If the component is animateable, add missing required styles from the 'from' prop to the base style
  if (animateable) {
    finalProps.animate = getKeys(stateStyles).reduce((final, key) => {
      if (getKeys(defaultRNStyles).includes(key)) {
        return {
          [key]: defaultRNStyles[key],
          ...removeUndefined(final)
        };
      }
      return final;
    }, finalProps.animate);

    // If the current state is true, add the state styles to the animate prop
    if (currentState) {
      finalProps.animate = {
        ...finalProps.animate,
        ...removeUndefined(stateStyles)
      };
    }
  } else {
    // If the component is not animateable and the current state is true, add the state styles to the style prop
    if (currentState) {
      if (activeComponentType !== "molecule") {
        finalProps.style = {
          ...finalProps.style,
          ...removeUndefined(stateStyles)
        };
      } else {
        finalProps = {
          ...finalProps,
          ...removeUndefined(stateStyles)
        };
      }
    }
  }
  return finalProps;
};
//# sourceMappingURL=useDynamicStateStyle.js.map