"use client" import { useAuth } from "@/contexts/auth-context" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Progress } from "@/components/ui/progress" import { BarChart3, Clock, Heart, ImageIcon, MessageSquare, FileText, TrendingUp, Trash2, RefreshCw } from "lucide-react" import { useState, useEffect } from "react" interface ActivityRecordsDialogProps { open: boolean onOpenChange: (open: boolean) => void } // Mock data for demonstration - will be replaced with real data const mockRecentApps: any[] = [] const mockCategoryData: any[] = [] export function ActivityRecordsDialog({ open, onOpenChange }: ActivityRecordsDialogProps) { const { user, getViewCount, getAppLikes, getUserLikeHistory, getAppLikesInPeriod } = useAuth() const [recentApps, setRecentApps] = useState([]) const [categoryData, setCategoryData] = useState([]) const [isResetting, setIsResetting] = useState(false) if (!user) return null // Calculate user statistics const calculateUserStats = () => { if (!user) return { totalUsage: 0, totalDuration: 0, favoriteApps: 0, daysJoined: 0 } // Calculate total usage count (views) const totalUsage = Object.values(user.recentApps || []).length // Calculate total duration (simplified - 5 minutes per app view) const totalDuration = totalUsage * 5 // minutes // Get favorite apps count const favoriteApps = user.favoriteApps?.length || 0 // Calculate days joined const joinDate = new Date(user.joinDate) const now = new Date() // Check if joinDate is valid let daysJoined = 0 if (!isNaN(joinDate.getTime())) { daysJoined = Math.floor((now.getTime() - joinDate.getTime()) / (1000 * 60 * 60 * 24)) } return { totalUsage, totalDuration, favoriteApps, daysJoined: Math.max(0, daysJoined) } } const stats = calculateUserStats() // Load recent apps from user's recent apps useEffect(() => { if (user?.recentApps) { // Convert recent app IDs to app objects (simplified) const recentAppsData = user.recentApps.slice(0, 10).map((appId, index) => ({ id: appId, name: `應用 ${appId}`, author: "系統", category: "AI應用", usageCount: getViewCount(appId), timeSpent: "5分鐘", lastUsed: `${index + 1}天前`, icon: MessageSquare, color: "bg-blue-500" })) setRecentApps(recentAppsData) } else { setRecentApps([]) } }, [user, getViewCount]) // Load category data (simplified) useEffect(() => { // This would normally be calculated from actual usage data setCategoryData([]) }, [user]) // Reset user activity data const resetActivityData = async () => { setIsResetting(true) try { // Clear localStorage data if (typeof window !== "undefined") { localStorage.removeItem("appViews") localStorage.removeItem("appLikes") localStorage.removeItem("userLikes") localStorage.removeItem("appLikesOld") localStorage.removeItem("appRatings") } // Reset user's recent apps and favorites if (user) { const updatedUser = { ...user, recentApps: [], favoriteApps: [], totalLikes: 0, totalViews: 0 } localStorage.setItem("user", JSON.stringify(updatedUser)) // Reload the page to refresh all data window.location.reload() } } catch (error) { console.error("Error resetting activity data:", error) } finally { setIsResetting(false) } } return ( 活動紀錄 最近使用 個人統計

最近使用的應用

您最近體驗過的 AI 應用

{recentApps.length > 0 ? (
{recentApps.map((app) => { const IconComponent = app.icon return (

{app.name}

by {app.author}

{app.category} 使用 {app.usageCount} 次 {app.timeSpent}

{app.lastUsed}

) })}
) : (

尚未使用任何應用

開始探索平台上的 AI 應用,您的使用記錄將顯示在這裡

)}

個人統計

您在平台上的活動概覽

{/* Statistics Cards */}
總使用次數
{isNaN(stats.totalUsage) ? 0 : stats.totalUsage}

{(isNaN(stats.totalUsage) ? 0 : stats.totalUsage) > 0 ? "累計使用" : "尚未使用任何應用"}

使用時長
{isNaN(stats.totalDuration) ? "0分鐘" : ( stats.totalDuration >= 60 ? `${(stats.totalDuration / 60).toFixed(1)}小時` : `${stats.totalDuration}分鐘` )}

{(isNaN(stats.totalDuration) ? 0 : stats.totalDuration) > 0 ? "累計時長" : "尚未開始使用"}

收藏應用
{isNaN(stats.favoriteApps) ? 0 : stats.favoriteApps}

{(isNaN(stats.favoriteApps) ? 0 : stats.favoriteApps) > 0 ? "個人收藏" : "尚未收藏任何應用"}

加入天數
{isNaN(stats.daysJoined) ? 0 : stats.daysJoined}

{(isNaN(stats.daysJoined) ? 0 : stats.daysJoined) > 0 ? "已加入平台" : "今天剛加入"}

{/* Category Usage */} 最常使用的類別 根據您的使用頻率統計的應用類別分布 {categoryData.length > 0 ? ( categoryData.map((category, index) => (
{category.name}
{category.usage}%
)) ) : (

尚未有使用數據

開始使用應用後,類別分布將顯示在這裡

)}
) }