/**
 * TabataFit StyledText
 * Unified text component — uses theme for default color
 */

import { Text as RNText, TextStyle, StyleProp } from 'react-native'
import { useThemeColors } from '../theme'

type FontWeight = 'regular' | 'medium' | 'semibold' | 'bold'

const WEIGHT_MAP: Record<FontWeight, TextStyle['fontWeight']> = {
  regular: '400',
  medium: '500',
  semibold: '600',
  bold: '700',
}

interface StyledTextProps {
  children: React.ReactNode
  size?: number
  weight?: FontWeight
  color?: string
  style?: StyleProp<TextStyle>
  numberOfLines?: number
}

export function StyledText({
  children,
  size = 17,
  weight = 'regular',
  color,
  style,
  numberOfLines,
}: StyledTextProps) {
  const colors = useThemeColors()
  const resolvedColor = color ?? colors.text.primary

  return (
    <RNText
      style={[
        {
          fontSize: size,
          fontWeight: WEIGHT_MAP[weight],
          color: resolvedColor,
        },
        style,
      ]}
      numberOfLines={numberOfLines}
    >
      {children}
    </RNText>
  )
}
