"use strict";

import { useEffect, useState } from 'react';
import { View, Text, StyleSheet, ScrollView, ActivityIndicator, TouchableOpacity } from 'react-native';
import { useOxy } from '../../context/OxyContext';
import Avatar from '../../components/Avatar';
import { Header } from '../../components';
import { useI18n } from '../../hooks/useI18n';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const KarmaLeaderboardScreen = ({
  goBack,
  theme,
  navigate
}) => {
  const {
    oxyServices
  } = useOxy();
  const {
    t
  } = useI18n();
  const [leaderboard, setLeaderboard] = useState([]);
  const [isLoading, setIsLoading] = useState(true);
  const [error, setError] = useState(null);
  const isDarkTheme = theme === 'dark';
  const backgroundColor = isDarkTheme ? '#121212' : '#FFFFFF';
  const textColor = isDarkTheme ? '#FFFFFF' : '#000000';
  const primaryColor = '#d169e5';
  useEffect(() => {
    setIsLoading(true);
    setError(null);
    oxyServices.getKarmaLeaderboard().then(data => setLeaderboard(Array.isArray(data) ? data : [])).catch(err => setError(err.message || 'Failed to load leaderboard')).finally(() => setIsLoading(false));
  }, [oxyServices]);
  return /*#__PURE__*/_jsxs(View, {
    style: [styles.container, {
      backgroundColor
    }],
    children: [/*#__PURE__*/_jsx(Header, {
      title: t('karma.leaderboard.title') || 'Karma Leaderboard',
      subtitle: t('karma.leaderboard.subtitle') || 'Top contributors in the community',
      theme: theme,
      onBack: goBack,
      elevation: "subtle"
    }), isLoading ? /*#__PURE__*/_jsx(ActivityIndicator, {
      size: "large",
      color: primaryColor,
      style: {
        marginTop: 40
      }
    }) : error ? /*#__PURE__*/_jsx(Text, {
      style: [styles.error, {
        color: '#D32F2F'
      }],
      children: error
    }) : /*#__PURE__*/_jsx(ScrollView, {
      contentContainerStyle: styles.listContainer,
      children: leaderboard.length === 0 ? /*#__PURE__*/_jsx(Text, {
        style: [styles.placeholder, {
          color: textColor
        }],
        children: t('karma.leaderboard.empty') || 'No leaderboard data.'
      }) : leaderboard.map((entry, idx) => /*#__PURE__*/_jsxs(TouchableOpacity, {
        style: [styles.row, idx < 3 && {
          backgroundColor: '#f7eaff'
        }],
        onPress: () => navigate && navigate('Profile', {
          userId: entry.userId,
          username: entry.username
        }),
        activeOpacity: 0.7,
        children: [/*#__PURE__*/_jsx(Text, {
          style: [styles.rank, {
            color: primaryColor
          }],
          children: idx + 1
        }), /*#__PURE__*/_jsx(Avatar, {
          name: entry.username || 'User',
          size: 40,
          theme: theme,
          style: styles.avatar
        }), /*#__PURE__*/_jsx(Text, {
          style: [styles.username, {
            color: textColor
          }],
          children: entry.username || entry.userId
        }), /*#__PURE__*/_jsx(Text, {
          style: [styles.karma, {
            color: primaryColor
          }],
          children: entry.total
        })]
      }, entry.userId))
    })]
  });
};
const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  listContainer: {
    paddingBottom: 40,
    paddingTop: 20
  },
  row: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingVertical: 12,
    paddingHorizontal: 20,
    borderBottomWidth: 1,
    borderColor: '#eee'
  },
  rank: {
    fontSize: 20,
    width: 32,
    textAlign: 'center',
    fontWeight: 'bold'
  },
  avatar: {
    marginHorizontal: 8
  },
  username: {
    flex: 1,
    fontSize: 16,
    marginLeft: 8
  },
  karma: {
    fontSize: 18,
    fontWeight: 'bold',
    marginLeft: 12
  },
  placeholder: {
    fontSize: 16,
    color: '#888',
    textAlign: 'center',
    marginTop: 40
  },
  error: {
    fontSize: 16,
    textAlign: 'center',
    marginTop: 40
  }
});
export default KarmaLeaderboardScreen;
//# sourceMappingURL=KarmaLeaderboardScreen.js.map