import React, { useState, useEffect } from 'react'; import { StorageService } from '../services/storageService'; import { UserProfile } from '../types'; import { Button } from '../components/ui/Button'; import { ShoppingBag, Star, Crown, Heart, TreePine, Dog, Sparkles, Lock, CheckCircle, Loader2, Coins, Palette, Compass, Flame, Zap, Calendar, Gift } from 'lucide-react'; import { useLanguage } from '../contexts/LanguageContext'; import confetti from 'canvas-confetti'; import { THEME_REGISTRY } from '../config/themes'; interface RewardItem { id: string; nameKey: string; cost: number; icon: React.FC; color: string; category: 'digital' | 'impact' | 'theme' | 'spiritual'; descriptionKey: string; } const ITEMS: RewardItem[] = [ { id: 'frame_gold', nameKey: 'Golden Avatar Frame', cost: 200, icon: Crown, color: 'text-yellow-500', category: 'digital', descriptionKey: 'Stand out with a royal golden border.' }, { id: 'pack_adventurer', nameKey: 'Adventurer Avatar Pack', cost: 500, icon: Compass, color: 'text-blue-600', category: 'digital', descriptionKey: 'Unlock the RPG-style Adventurer avatar collection.' }, { id: 'theme_rudra', nameKey: 'Rudra Eternal', cost: 400, icon: Flame, color: 'text-orange-600', category: 'spiritual', descriptionKey: 'Premium dark theme dedicated to Lord Shiva.' }, { id: 'theme_divine', nameKey: 'Divine Radiance', cost: 450, icon: SunIcon, color: 'text-yellow-400', category: 'spiritual', descriptionKey: 'Glow with celestial light and spiritual energy.' }, { id: 'theme_buddha', nameKey: "Buddha's Path", cost: 350, icon: Sparkles, color: 'text-red-500', category: 'spiritual', descriptionKey: 'Serene heritage theme with a peaceful aesthetic.' }, { id: 'theme_cyberpunk', nameKey: 'Cyber Protocol', cost: 400, icon: Zap, color: 'text-pink-500', category: 'theme', descriptionKey: 'Futuristic Tech aesthetic.' }, { id: 'theme_royal', nameKey: 'Royal Palace', cost: 450, icon: Crown, color: 'text-purple-600', category: 'theme', descriptionKey: 'Gilded palace interior vibes.' }, { id: 'theme_gold', nameKey: 'Golden Karma', cost: 600, icon: Coins, color: 'text-amber-500', category: 'theme', descriptionKey: 'Solid gold UI for the masters.' }, { id: 'theme_obsidian', nameKey: 'Black Velvet', cost: 750, icon: Lock, color: 'text-gray-900', category: 'theme', descriptionKey: 'Absolute pitch black premium skin.' }, { id: 'donate_dog', nameKey: 'Feed a Stray Dog', cost: 100, icon: Dog, color: 'text-orange-600', category: 'impact', descriptionKey: 'We donate Rs. 10 to a local shelter.' }, { id: 'donate_tree', nameKey: 'Plant a Tree', cost: 250, icon: TreePine, color: 'text-green-600', category: 'impact', descriptionKey: 'Contribute to reforestation projects.' }, { id: 'donate_orphan', nameKey: 'Donate to Orphanage', cost: 1000, icon: Heart, color: 'text-pink-600', category: 'impact', descriptionKey: 'Provide school supplies for a child.' }, ]; function SunIcon(props: any) { return ( ); } const Rewards: React.FC = () => { const { t } = useLanguage(); const [profile, setProfile] = useState(null); const [loading, setLoading] = useState(true); const [redeeming, setRedeeming] = useState(null); const [claimingDaily, setClaimingDaily] = useState(false); useEffect(() => { loadProfile(); }, []); const loadProfile = async () => { setLoading(true); const p = await StorageService.getProfile(); setProfile(p); setLoading(false); }; const handleRedeem = async (item: RewardItem) => { if (!profile) return; setRedeeming(item.id); setTimeout(async () => { const { success, error } = await StorageService.redeemReward(item.id, item.cost); if (success) { setProfile(prev => prev ? { ...prev, points: prev.points - item.cost, unlockedItems: [...(prev.unlockedItems || []), item.id] } : null); confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 }, colors: ['#FFD700', '#FFA500'] }); window.dispatchEvent(new Event('rudraksha-profile-update')); } else { alert(error || t("Insufficient Karma", "Insufficient Karma")); } setRedeeming(null); }, 800); }; const handleEquipTheme = async (themeId: string) => { if (!profile) return; setRedeeming(themeId); const newTheme = profile.activeTheme === themeId ? 'default' : themeId; const updated = await StorageService.updateProfile({ activeTheme: newTheme }); setProfile(updated); setRedeeming(null); window.dispatchEvent(new Event('rudraksha-profile-update')); }; const handleDailyClaim = async () => { setClaimingDaily(true); const res = await StorageService.claimDailyBonus(); if (res.success) { confetti({ particleCount: 150, spread: 100, origin: { y: 0.3 } }); const p = await StorageService.getProfile(); setProfile(p); alert(res.message); } else { alert(res.message); } setClaimingDaily(false); }; if (loading) return
; if (!profile) return null; return (

{t("Karma Bazaar", "Karma Bazaar")}

{t("Redeem your hard-earned points for digital goods or social impact.", "Redeem your hard-earned points for digital goods or social impact.")}

{t("Balance", "Balance")}

{profile.points}

Spiritual Aesthetics

{ITEMS.filter(i => i.category === 'spiritual').map((item, idx) => (
))}

Premium Skins

{ITEMS.filter(i => i.category === 'theme').map((item, idx) => (
))}

{t("Digital Goods", "Digital Goods")}

{ITEMS.filter(i => i.category === 'digital').map((item, idx) => (
))}

{t("Social Impact", "Social Impact")}

{ITEMS.filter(i => i.category === 'impact').map((item, idx) => (
))}
); }; const RewardCard: React.FC<{ item: RewardItem, profile: UserProfile, onRedeem: (i: RewardItem) => void, onEquip: (id: string) => void, redeeming: string | null, t: any }> = ({ item, profile, onRedeem, onEquip, redeeming, t }) => { const isOwned = profile.unlockedItems?.includes(item.id); const canAfford = profile.points >= item.cost; const isRedeeming = redeeming === item.id; const isTheme = item.category === 'theme' || item.category === 'spiritual'; const isEquipped = profile.activeTheme === item.id; return (
{isOwned ? : }

{t(item.nameKey, item.nameKey)}

{t(item.descriptionKey, item.descriptionKey)}

{item.cost} {isOwned && isTheme ? ( ) : isOwned && item.category === 'digital' ? ( {t("Owned", "Owned")} ) : ( )}
); }; export default Rewards;