"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _fonts = require("../../styles/fonts");
var _vectorIcons = require("@expo/vector-icons");
var _useI18n = require("../../hooks/useI18n");
var _useThemeStyles = require("../../hooks/useThemeStyles");
var _useColorScheme = require("../../hooks/use-color-scheme");
var _colorUtils = require("../../utils/colorUtils");
var _OxyContext = require("../../context/OxyContext");
var _jsxRuntime = require("react/jsx-runtime");
const KarmaCenterScreen = ({
  theme,
  navigate,
  goBack
}) => {
  // Use useOxy() hook for OxyContext values
  const {
    user,
    oxyServices,
    isAuthenticated
  } = (0, _OxyContext.useOxy)();
  const {
    t
  } = (0, _useI18n.useI18n)();
  const [karmaTotal, setKarmaTotal] = (0, _react.useState)(null);
  const [karmaHistory, setKarmaHistory] = (0, _react.useState)([]);
  const [isLoading, setIsLoading] = (0, _react.useState)(true);
  const [error, setError] = (0, _react.useState)(null);
  const colorScheme = (0, _useColorScheme.useColorScheme)();
  const themeStyles = (0, _useThemeStyles.useThemeStyles)(theme || 'light', colorScheme);
  // Override primaryColor for Karma screens (purple instead of blue)
  const primaryColor = '#d169e5';

  // Icon colors from theme
  const iconLeaderboard = themeStyles.colors.iconPayments;
  const iconRules = themeStyles.colors.iconSecurity;
  const iconAbout = themeStyles.colors.iconPayments;
  const iconRewards = themeStyles.colors.iconStorage;
  const iconFAQ = themeStyles.colors.iconPersonalInfo;
  (0, _react.useEffect)(() => {
    if (!user) return;
    setIsLoading(true);
    setError(null);
    Promise.all([oxyServices.getUserKarmaTotal(user.id), oxyServices.getUserKarmaHistory(user.id, 20, 0)]).then(([totalRes, historyRes]) => {
      setKarmaTotal(totalRes.total);
      setKarmaHistory(Array.isArray(historyRes.history) ? historyRes.history : []);
    }).catch(err => {
      setError(err.message || 'Failed to load karma data');
    }).finally(() => setIsLoading(false));
  }, [user]);
  if (!isAuthenticated) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: [styles.container, {
        backgroundColor: themeStyles.backgroundColor
      }],
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.message, {
          color: themeStyles.textColor
        }],
        children: t('common.status.notSignedIn') || 'Not signed in'
      })
    });
  }
  if (isLoading) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: [styles.container, {
        backgroundColor: themeStyles.backgroundColor,
        justifyContent: 'center'
      }],
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
        size: "large",
        color: primaryColor
      })
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [styles.container, {
      backgroundColor: themeStyles.backgroundColor
    }],
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, {
      style: styles.scrollView,
      contentContainerStyle: styles.scrollContainer,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
        style: styles.walletHeader,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: [styles.karmaAmount, {
            color: primaryColor
          }],
          children: karmaTotal ?? 0
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: [styles.karmaLabel, {
            color: themeStyles.isDarkTheme ? '#BBBBBB' : '#888888'
          }],
          children: t('karma.center.balance') || 'Karma Balance'
        }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
          style: styles.actionContainer,
          children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
            style: styles.actionRow,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
              style: styles.actionIconWrapper,
              onPress: () => navigate && navigate('KarmaLeaderboard'),
              children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
                style: [styles.actionIcon, {
                  backgroundColor: iconLeaderboard
                }],
                children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
                  name: "trophy-outline",
                  size: 28,
                  color: (0, _colorUtils.darkenColor)(iconLeaderboard)
                })
              }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                style: styles.actionLabel,
                children: t('karma.center.actions.leaderboard') || 'Leaderboard'
              })]
            }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
              style: styles.actionIconWrapper,
              onPress: () => navigate && navigate('KarmaRules'),
              children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
                style: [styles.actionIcon, {
                  backgroundColor: iconRules
                }],
                children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
                  name: "document-text-outline",
                  size: 28,
                  color: (0, _colorUtils.darkenColor)(iconRules)
                })
              }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                style: styles.actionLabel,
                children: t('karma.center.actions.rules') || 'Rules'
              })]
            }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
              style: styles.actionIconWrapper,
              onPress: () => navigate && navigate('AboutKarma'),
              children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
                style: [styles.actionIcon, {
                  backgroundColor: iconAbout
                }],
                children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
                  name: "star-outline",
                  size: 28,
                  color: (0, _colorUtils.darkenColor)(iconAbout)
                })
              }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                style: styles.actionLabel,
                children: t('karma.center.actions.about') || 'About'
              })]
            })]
          }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
            style: styles.actionRow,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
              style: styles.actionIconWrapper,
              onPress: () => navigate && navigate('KarmaRewards'),
              children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
                style: [styles.actionIcon, {
                  backgroundColor: iconRewards
                }],
                children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
                  name: "gift-outline",
                  size: 28,
                  color: (0, _colorUtils.darkenColor)(iconRewards)
                })
              }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                style: styles.actionLabel,
                children: t('karma.center.actions.rewards') || 'Rewards'
              })]
            }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
              style: styles.actionIconWrapper,
              onPress: () => navigate && navigate('KarmaFAQ'),
              children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
                style: [styles.actionIcon, {
                  backgroundColor: iconFAQ
                }],
                children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
                  name: "help-circle-outline",
                  size: 28,
                  color: (0, _colorUtils.darkenColor)(iconFAQ)
                })
              }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                style: styles.actionLabel,
                children: t('karma.center.actions.faq') || 'FAQ'
              })]
            })]
          })]
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: styles.infoText,
          children: t('karma.center.info') || 'Karma can only be earned by positive actions in the Oxy Ecosystem. It cannot be sent or received directly.'
        })]
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.sectionTitle, {
          color: themeStyles.textColor
        }],
        children: t('karma.center.history') || 'Karma History'
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
        style: styles.historyContainer,
        children: karmaHistory.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: {
            color: themeStyles.textColor,
            textAlign: 'center',
            marginTop: 16
          },
          children: t('karma.center.noHistory') || 'No karma history yet.'
        }) : karmaHistory.map(entry => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
          style: [styles.historyItem, {
            borderColor: themeStyles.borderColor
          }],
          children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, {
            style: [styles.historyPoints, {
              color: entry.points > 0 ? primaryColor : '#D32F2F'
            }],
            children: [entry.points > 0 ? '+' : '', entry.points]
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
            style: [styles.historyDesc, {
              color: themeStyles.textColor
            }],
            children: entry.reason || t('karma.center.noDescription') || 'No description'
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
            style: [styles.historyDate, {
              color: themeStyles.isDarkTheme ? '#BBBBBB' : '#888888'
            }],
            children: entry.createdAt ? new Date(entry.createdAt).toLocaleString() : ''
          })]
        }, entry.id))
      }), error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: {
          color: '#D32F2F',
          marginTop: 16,
          textAlign: 'center'
        },
        children: error
      })]
    })
  });
};
const styles = _reactNative.StyleSheet.create({
  container: {
    flex: 1
  },
  scrollView: {
    flex: 1
  },
  scrollContainer: {
    padding: 0,
    alignItems: 'center'
  },
  walletHeader: {
    alignItems: 'center',
    paddingTop: 36,
    paddingBottom: 24,
    width: '100%',
    backgroundColor: 'transparent'
  },
  karmaLabel: {
    fontSize: 16,
    marginBottom: 18,
    fontFamily: _fonts.fontFamilies.phudu
  },
  karmaAmount: {
    fontSize: 48,
    fontWeight: 'bold',
    marginBottom: 4,
    fontFamily: _fonts.fontFamilies.phudu
  },
  actionContainer: {
    marginBottom: 18,
    gap: 8
  },
  actionRow: {
    flexDirection: 'row',
    justifyContent: 'center',
    gap: 2
  },
  actionIconWrapper: {
    alignItems: 'center',
    width: 72
  },
  actionIcon: {
    width: 56,
    height: 56,
    borderRadius: 28,
    alignItems: 'center',
    justifyContent: 'center',
    marginBottom: 6
  },
  actionIconText: {
    fontSize: 28
  },
  actionLabel: {
    fontSize: 10,
    color: '#888'
  },
  infoText: {
    fontSize: 13,
    color: '#888',
    textAlign: 'center',
    marginTop: 8,
    marginBottom: 8,
    maxWidth: 320
  },
  sectionTitle: {
    fontSize: 18,
    fontWeight: '600',
    marginBottom: 12,
    marginTop: 8,
    alignSelf: 'flex-start',
    marginLeft: 24
  },
  historyContainer: {
    borderRadius: 15,
    overflow: 'hidden',
    marginBottom: 20,
    width: '100%',
    paddingHorizontal: 12
  },
  historyItem: {
    padding: 14,
    borderBottomWidth: 1
  },
  historyPoints: {
    fontSize: 16,
    fontWeight: '700'
  },
  historyDesc: {
    fontSize: 15,
    marginTop: 2
  },
  historyDate: {
    fontSize: 13,
    marginTop: 2
  },
  message: {
    fontSize: 16,
    textAlign: 'center',
    marginTop: 24
  }
});
var _default = exports.default = KarmaCenterScreen;
//# sourceMappingURL=KarmaCenterScreen.js.map