"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IOText = exports.AnimatedIOText = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireDefault(require("react-native-reanimated"));
var _context = require("../../context");
var _core = require("../../core");
var _accessibility = require("../../utils/accessibility");
var _fonts = require("../../utils/fonts");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
 * We exclude all of the following props when we define a new
 * typographic style in which all of these visual attributes
 * are already defined.
 */

/**
 * The specific properties needed to calculate the font style using {@link makeFontStyleObject} (these information
 * cannot be included in the default StyleProp<TextStyle>
 */

/**
 * Extend `TypographicStyleProps` with extra props for styles that
 * can be used as links
 */

/**
 * Decorate the function {@link makeFontStyleObject} with the additional color calculation.
 * @param color A value key from {@link IOColors}, transformed here in {@link ColorValue}
 * @param args the args of the function {@link makeFontStyleObject}
 */
const calculateTextStyle = (color, ...args) => ({
  ...(0, _fonts.makeFontStyleObject)(...args),
  color: color ? _core.IOColors[color] : undefined
});

/**
 * `IOText` is the core Typography component used to render a text.
 * It accepts all the default text style `StyleProp<TextStyle>` (excluding the ones already applied) in addition with {@link IOTextBaseProps}
 * used to calculate at runtime the platform-dependent styles.
 * @param props
 * @constructor
 */
const IOText = exports.IOText = /*#__PURE__*/(0, _react.forwardRef)(({
  color,
  size,
  font,
  lineHeight,
  weight,
  fontStyle,
  textStyle,
  style,
  children,
  allowFontScaling = true,
  maxFontSizeMultiplier,
  ...props
}, ref) => {
  const boldEnabled = (0, _accessibility.useBoldTextEnabled)();
  const {
    newTypefaceEnabled
  } = (0, _context.useIONewTypeface)();
  const computedFont = font || (newTypefaceEnabled ? "Titillio" : "TitilliumSansPro");
  const computedStyleObj = (0, _react.useMemo)(() => calculateTextStyle(color, size, computedFont, lineHeight, weight, fontStyle, boldEnabled), [color, size, computedFont, lineHeight, weight, fontStyle, boldEnabled]);

  /* In some cases, for example when we use color transitions with
  `reanimated` we need to manage chromatic values as `ColorValue`
  or `string` (not `IOColors`). So we keep a way to override
  the the `color' attribute without giving the ability to
  override all other all other typographic attributes
  through the `style' prop. */
  const fontStyleObj = style?.color ? [{
    ...computedStyleObj,
    color: style?.color
  }] : computedStyleObj;

  /* Some typographic styles like `H5` have certain `TextStyle` properties
   like `textTransform` or `letterSpacing` that we want to apply to the text.
   We use the `textStyle` prop to pass these properties to the `IOText`
   component and preserve the ability to define the `style` prop as well.
   The `style` prop is the last one to be applied, so we can properly
   override the `color` attribute.
   */
  const styleObj = style ? [textStyle ?? {}, fontStyleObj ?? {}, style] : [textStyle ?? {}, fontStyleObj ?? {}];

  /* Accessible typography based on the `fontScale` parameter */
  const accessibleFontSizeProps = {
    allowFontScaling,
    maxFontSizeMultiplier: maxFontSizeMultiplier ?? _fonts.IOMaxFontSizeMultiplier
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
    ref: ref,
    style: styleObj,
    ...props,
    ...accessibleFontSizeProps,
    children: children
  });
});
const AnimatedIOText = exports.AnimatedIOText = _reactNativeReanimated.default.createAnimatedComponent(IOText);
//# sourceMappingURL=IOText.js.map