import { useLanguage } from '@/common/hooks/useStrings';
import { Text as RNText, TextProps, StyleSheet, TextStyle } from 'react-native';

const FONT_SCALE = 1.15;

const fonts = {
  en: { base: 'CormorantGaramond_600SemiBold', bold: 'CormorantGaramond_700Bold' },
  ko: { base: 'NanumMyeongjo_400Regular', bold: 'NanumMyeongjo_700Bold' },
};

export function Text({ style, ...props }: TextProps) {
  const { language } = useLanguage();
  const flat = StyleSheet.flatten(style) as TextStyle | undefined;
  const size = (flat?.fontSize ?? 14) * FONT_SCALE;
  const weight = flat?.fontWeight;
  const { base, bold } = fonts[language];
  const font = weight === '600' || weight === '700' || weight === 'bold' ? bold : base;
  const { fontWeight: _, ...rest } = flat ?? {};

  return <RNText style={[rest, { fontFamily: font, fontSize: size }]} {...props} />;
}
