import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Progress } from '@/components/ui/progress'; import { Separator } from '@/components/ui/separator'; import { Badge } from '@/components/ui/badge'; import { useToast } from '@/hooks/use-toast'; import { useAuth } from '@/hooks/useAuth'; import { supabase } from '@/integrations/supabase/client'; import { Download, BarChart3, Upload, FileText, History } from 'lucide-react'; export function DataExportTab() { const { user, profile } = useAuth(); const { toast } = useToast(); const [exportLoading, setExportLoading] = useState(false); const [exportProgress, setExportProgress] = useState(0); const handleDataExport = async () => { if (!user) return; setExportLoading(true); setExportProgress(0); try { // Simulate export progress const steps = ['Collecting profile data...', 'Gathering reviews...', 'Collecting ride credits...', 'Gathering top lists...', 'Packaging data...', 'Preparing download...']; for (let i = 0; i < steps.length; i++) { await new Promise(resolve => setTimeout(resolve, 500)); setExportProgress((i + 1) / steps.length * 100); } // In a real implementation, this would: // 1. Fetch all user data from various tables // 2. Package it into a structured format (JSON/CSV) // 3. Create a downloadable file const exportData = { profile: profile, export_date: new Date().toISOString(), data_types: ['profile', 'reviews', 'ride_credits', 'top_lists'] }; const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `thrillwiki-data-export-${new Date().toISOString().split('T')[0]}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); toast({ title: 'Export complete', description: 'Your data has been exported and downloaded successfully.' }); } catch (error: any) { toast({ title: 'Export failed', description: error.message || 'Failed to export your data', variant: 'destructive' }); } finally { setExportLoading(false); setExportProgress(0); } }; const handleImportData = () => { toast({ title: 'Coming soon', description: 'Data import functionality will be available in a future update.' }); }; return
Your data will be provided in JSON format. Processing may take a few moments for accounts with lots of activity.
Profile updated
{profile?.updated_at ? new Date(profile.updated_at).toLocaleString() : 'Recently'}
Account created
{profile?.created_at ? new Date(profile.created_at).toLocaleString() : 'N/A'}