import { Text, View } from '@tarojs/components'
import { formatCount } from '@/utils/date'
import type { UserProfile } from '@/types/domain'
import './index.scss'

type StatKey = 'posts' | 'following' | 'followers'

interface StatsRowProps {
  stats: UserProfile['stats']
  onSelect?: (key: StatKey) => void
}

const labels: Array<[StatKey, string]> = [
  ['posts', '动态'],
  ['following', '关注'],
  ['followers', '粉丝']
]

export function StatsRow({ stats, onSelect }: StatsRowProps) {
  const safeStats = stats || { posts: 0, following: 0, followers: 0 }
  return (
    <View className='stats-row'>
      {labels.map(([key, label]) => (
        <View key={key} className='stats-row__item' onClick={() => onSelect?.(key)}>
          <Text className='stats-row__num'>{formatCount(safeStats[key])}</Text>
          <Text className='stats-row__label'>{label}</Text>
        </View>
      ))}
    </View>
  )
}

export default StatsRow
