import { useEffect, useState, useCallback } from "react"; import { useDiscordActivity } from "@/contexts/DiscordActivityContext"; import LoadingScreen from "@/components/LoadingScreen"; import { Heart, MessageCircle, Trophy, Zap, Gamepad2, Briefcase, BookOpen, Network, Sparkles, Shield, RefreshCw, ExternalLink, Flame, Star, Target, Gift, CheckCircle, AlertCircle, Loader2, ChevronRight, } from "lucide-react"; const APP_URL = "https://aethex.dev"; type ArmType = "labs" | "gameforge" | "corp" | "foundation" | "devlink" | "nexus" | "staff"; const ARM_CONFIG: Record = { labs: { label: "Labs", icon: Zap, color: "#facc15", accent: "bg-yellow-500" }, gameforge: { label: "GameForge", icon: Gamepad2, color: "#4ade80", accent: "bg-green-500" }, corp: { label: "Corp", icon: Briefcase, color: "#60a5fa", accent: "bg-blue-500" }, foundation: { label: "Foundation", icon: BookOpen, color: "#f87171", accent: "bg-red-500" }, devlink: { label: "Dev-Link", icon: Network, color: "#22d3ee", accent: "bg-cyan-500" }, nexus: { label: "Nexus", icon: Sparkles, color: "#c084fc", accent: "bg-purple-500" }, staff: { label: "Staff", icon: Shield, color: "#818cf8", accent: "bg-indigo-500" }, }; interface Post { id: string; title: string; content: string; arm_affiliation: ArmType; author_id: string; created_at: string; likes_count: number; comments_count: number; tags?: string[]; user_profiles?: { id: string; username?: string; full_name?: string; avatar_url?: string }; } interface Quest { id: string; title: string; description: string; xp_reward: number; completed: boolean; progress: number; total: number; type: "daily" | "weekly"; } interface Achievement { id: string; name: string; description: string; icon: string; xp_reward: number; unlocked: boolean; progress?: number; total?: number; } interface LeaderboardEntry { rank: number; user_id: string; username: string; xp: number; level: number; streak?: number; } function FeedTab({ openExternalLink }: { openExternalLink: (url: string) => Promise }) { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchPosts = useCallback(async () => { setLoading(true); setError(null); try { const response = await fetch("/api/feed?limit=8"); if (!response.ok) throw new Error("Failed to load"); const data = await response.json(); setPosts(data.data || []); } catch { setError("Couldn't load feed"); } finally { setLoading(false); } }, []); useEffect(() => { fetchPosts(); }, [fetchPosts]); if (loading) return
; if (error) return (

{error}

); return (
{posts.length === 0 ? ( ) : ( posts.map((post) => { const config = ARM_CONFIG[post.arm_affiliation] || ARM_CONFIG.labs; return ( ); }) )}
); } function RealmsTab({ currentRealm, openExternalLink }: { currentRealm: ArmType; openExternalLink: (url: string) => Promise }) { const realms = Object.entries(ARM_CONFIG) as [ArmType, typeof ARM_CONFIG[ArmType]][]; return (
{realms.map(([key, config]) => { const Icon = config.icon; const isActive = currentRealm === key; return ( ); })}
); } function BadgesTab({ openExternalLink }: { openExternalLink: (url: string) => Promise }) { const achievements: Achievement[] = [ { id: "1", name: "First Post", description: "Create your first post", icon: "πŸ“", xp_reward: 50, unlocked: true }, { id: "2", name: "Social Butterfly", description: "Follow 5 realms", icon: "πŸ¦‹", xp_reward: 100, unlocked: true }, { id: "3", name: "Realm Explorer", description: "Visit all 7 realms", icon: "πŸ—ΊοΈ", xp_reward: 150, unlocked: false, progress: 5, total: 7 }, { id: "4", name: "Community Leader", description: "Get 100 likes", icon: "πŸ‘‘", xp_reward: 500, unlocked: false, progress: 42, total: 100 }, ]; return (
{achievements.map((a) => (
{a.icon}
{a.name} +{a.xp_reward} XP

{a.description}

{!a.unlocked && a.progress !== undefined && (
{a.progress}/{a.total}
)}
{a.unlocked && }
))}
); } function TopTab({ openExternalLink }: { openExternalLink: (url: string) => Promise }) { const leaderboard: LeaderboardEntry[] = [ { rank: 1, user_id: "1", username: "CodeMaster", xp: 12500, level: 25, streak: 14 }, { rank: 2, user_id: "2", username: "DevNinja", xp: 11200, level: 23, streak: 7 }, { rank: 3, user_id: "3", username: "BuilderX", xp: 9800, level: 21, streak: 21 }, { rank: 4, user_id: "4", username: "CreatorPro", xp: 8500, level: 19, streak: 5 }, { rank: 5, user_id: "5", username: "ForgeHero", xp: 7200, level: 17, streak: 3 }, ]; const medals = ["πŸ₯‡", "πŸ₯ˆ", "πŸ₯‰"]; return (
{leaderboard.map((entry) => (
{medals[entry.rank - 1] || `#${entry.rank}`}

{entry.username}

Lvl {entry.level} Β· {entry.xp.toLocaleString()} XP

{entry.streak && entry.streak > 0 && ( {entry.streak}d )}
))}
); } function JobsTab({ openExternalLink }: { openExternalLink: (url: string) => Promise }) { const categories = [ { label: "Full-Time", icon: Briefcase }, { label: "Contract", icon: Target }, { label: "Freelance", icon: Star }, ]; return (

Browse opportunities from the AeThex community.

{categories.map(({ label, icon: Icon }) => ( ))}
); } function QuestsTab({ openExternalLink }: { openExternalLink: (url: string) => Promise }) { const quests: Quest[] = [ { id: "1", title: "Share Your Work", description: "Post an update", xp_reward: 25, completed: false, progress: 0, total: 1, type: "daily" }, { id: "2", title: "Engage & Support", description: "Like 5 posts", xp_reward: 15, completed: false, progress: 3, total: 5, type: "daily" }, { id: "3", title: "Realm Hopper", description: "Visit 3 realms", xp_reward: 20, completed: true, progress: 3, total: 3, type: "daily" }, { id: "4", title: "Weekly Contributor", description: "Make 7 posts", xp_reward: 150, completed: false, progress: 4, total: 7, type: "weekly" }, ]; return (
{quests.map((q) => (
{q.completed ? : } {q.title}
+{q.xp_reward} XP
{!q.completed && (
{q.progress}/{q.total}
)}
))}
); } export default function Activity() { const { isActivity, isLoading, user, error, openExternalLink } = useDiscordActivity(); const [activeTab, setActiveTab] = useState("feed"); const currentRealm: ArmType = (user?.primary_arm as ArmType) || "labs"; if (isLoading) return ; if (error) return (

Something went wrong

{error}

); if (!isActivity) return (

Discord Activity

Open this within Discord to get started.

Visit aethex.dev
); const tabs = [ { id: "feed", label: "Feed" }, { id: "realms", label: "Realms" }, { id: "badges", label: "Badges" }, { id: "top", label: "Top" }, { id: "jobs", label: "Jobs" }, { id: "quests", label: "Quests" }, ]; const realmConfig = ARM_CONFIG[currentRealm]; const RealmIcon = realmConfig.icon; return (
{user?.avatar_url && }

{user?.full_name || user?.username}

{realmConfig.label}
{tabs.map((tab) => ( ))}
{activeTab === "feed" && } {activeTab === "realms" && } {activeTab === "badges" && } {activeTab === "top" && } {activeTab === "jobs" && } {activeTab === "quests" && }
); }