"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useDynamicStateStyle = void 0;
var _styleFunctions = require("../../theme/src/style-functions");
var _defaultRnStyles = _interopRequireDefault(require("../../theme/utils/default-rn-styles"));
var _typeHelpers = require("../../theme/utils/type-helpers");
var _utils = require("../../theme/utils/utils");
var _useStateWithStyleProps = require("../useStateWithStyleProps");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
 * 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
 */
const useDynamicStateStyle = (props, stateKey, currentState, styleFunctions = _styleFunctions.boxStyleFunctions, activeComponentType = "basic", animateable = true) => {
  // Override the pressed state if the parentStateValue is provided
  let stateStyles = (0, _useStateWithStyleProps.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 = (0, _typeHelpers.getKeys)(stateStyles).reduce((final, key) => {
      if ((0, _typeHelpers.getKeys)(_defaultRnStyles.default).includes(key)) {
        return {
          [key]: _defaultRnStyles.default[key],
          ...(0, _utils.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,
        ...(0, _utils.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,
          ...(0, _utils.removeUndefined)(stateStyles)
        };
      } else {
        finalProps = {
          ...finalProps,
          ...(0, _utils.removeUndefined)(stateStyles)
        };
      }
    }
  }
  return finalProps;
};
exports.useDynamicStateStyle = useDynamicStateStyle;
//# sourceMappingURL=useDynamicStateStyle.js.map