"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _styles = require("../styles");
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); }
// Helper function for text color
const getTextColor = (colors, disabled, type) => {
  if (type === 'error') {
    return colors.error;
  }
  if (disabled) {
    return colors.secondaryText + '80'; // Add opacity
  }
  return colors.secondaryText;
};
/**
 * Helper text is used in conjunction with input elements to provide additional hints for the user.
 */
const HelperText = ({
  style,
  type = 'info',
  visible = true,
  theme: themeProp = 'light',
  onLayout,
  padding = 'normal',
  disabled,
  maxFontSizeMultiplier = 1.5,
  ...rest
}) => {
  const colors = (0, _styles.useThemeColors)(themeProp);
  const {
    current: shown
  } = React.useRef(new _reactNative.Animated.Value(visible ? 1 : 0));
  let {
    current: textHeight
  } = React.useRef(0);
  React.useEffect(() => {
    if (visible) {
      // show text
      _reactNative.Animated.timing(shown, {
        toValue: 1,
        duration: 150,
        useNativeDriver: true
      }).start();
    } else {
      // hide text
      _reactNative.Animated.timing(shown, {
        toValue: 0,
        duration: 180,
        useNativeDriver: true
      }).start();
    }
  }, [visible, shown]);
  const handleTextLayout = e => {
    onLayout?.(e);
    textHeight = e.nativeEvent.layout.height;
  };

  // Get text color based on type and disabled state
  const getTextColor = () => {
    if (type === 'error') {
      return colors.error;
    }
    if (disabled) {
      return colors.secondaryText + '80'; // Add opacity
    }
    return colors.secondaryText;
  };
  const textColor = getTextColor();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.Text, {
    onLayout: handleTextLayout,
    style: [styles.text, padding !== 'none' ? styles.padding : {}, {
      color: textColor,
      opacity: shown,
      transform: visible && type === 'error' ? [{
        translateY: shown.interpolate({
          inputRange: [0, 1],
          outputRange: [-textHeight / 2, 0]
        })
      }] : []
    }, style],
    maxFontSizeMultiplier: maxFontSizeMultiplier,
    ...rest,
    children: rest.children
  });
};
const styles = _reactNative.StyleSheet.create({
  text: {
    fontSize: 12,
    paddingVertical: 4
  },
  padding: {
    paddingHorizontal: 12
  }
});
var _default = exports.default = HelperText;
//# sourceMappingURL=HelperText.js.map