function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import * as React from 'react';
import { Text as NativeText, StyleSheet, I18nManager, Platform } from 'react-native';
import { useTheme } from '../core/theming';
import { BodyType, HeadlinesType } from '../types';
const Text = (_ref, ref) => {
  let {
    style,
    variant,
    theme: initialTheme,
    ...rest
  } = _ref;
  const root = React.useRef(null);
  // FIXME: destructure it in TS 4.6+
  const theme = useTheme(initialTheme);
  const writingDirection = I18nManager.isRTL ? 'rtl' : 'ltr';
  React.useImperativeHandle(ref, () => ({
    setNativeProps: args => {
      var _root$current;
      return (_root$current = root.current) === null || _root$current === void 0 ? void 0 : _root$current.setNativeProps(args);
    }
  }));
  if (variant) {
    const stylesByVariant = Object.keys(Object.assign({}, HeadlinesType, BodyType)).reduce((acc, key) => {
      const {
        fontSize,
        fontWeight,
        lineHeight,
        letterSpacing,
        fontFamily
      } = theme.typescale[key];
      return {
        ...acc,
        [key]: {
          ...(Platform.OS === 'android' && {
            fontFamily
          }),
          fontSize,
          fontWeight,
          lineHeight,
          letterSpacing,
          color: theme.colors.onSurface
        }
      };
    }, {});
    const styleForVariant = stylesByVariant[variant];
    return /*#__PURE__*/React.createElement(NativeText, _extends({
      ref: root,
      style: [styleForVariant, styles.text, {
        writingDirection
      }, style]
    }, rest));
  } else {
    var _theme$fonts;
    return /*#__PURE__*/React.createElement(NativeText, _extends({}, rest, {
      ref: root,
      style: [{
        ...((_theme$fonts = theme.fonts) === null || _theme$fonts === void 0 ? void 0 : _theme$fonts.regular),
        color: theme.colors.text
      }, styles.text, style]
    }));
  }
};
const styles = StyleSheet.create({
  text: {
    textAlign: 'left'
  }
});
export default /*#__PURE__*/React.forwardRef(Text);
//# sourceMappingURL=Text.js.map