"use client" import { useState, useEffect } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Textarea } from "@/components/ui/textarea" import { Switch } from "@/components/ui/switch" import { User, Shield, Bell, Palette, Globe, Database, Key, Download, Upload, Trash2, Save, RefreshCw, AlertTriangle, CheckCircle, Eye, EyeOff, Copy, ExternalLink, HardDrive, Activity, Lock, Smartphone, Plus, X, } from "lucide-react" export default function SettingsPage() { const [activeTab, setActiveTab] = useState("profile") const [showAddDeviceModal, setShowAddDeviceModal] = useState(false) const [showExportConfirmation, setShowExportConfirmation] = useState(false) const [settings, setSettings] = useState({ profile: { firstName: "Utilisateur", lastName: "Démo", email: "demo@docv.fr", phone: "+33 1 23 45 67 89", position: "Administrateur", department: "Direction", bio: "Utilisateur de démonstration pour DocV", }, security: { twoFactorEnabled: true, sessionTimeout: "30", passwordLastChanged: new Date("2024-01-01"), activeDevices: 1, // Simuler un seul device }, notifications: { emailNotifications: true, pushNotifications: true, documentUpdates: true, folderSharing: true, systemAlerts: true, weeklyReport: false, }, appearance: { theme: "light", language: "fr", timezone: "Europe/Paris", dateFormat: "dd/mm/yyyy", compactMode: false, }, privacy: { profileVisibility: "team", activityTracking: true, dataSharing: false, analyticsOptIn: true, }, storage: { used: 67.3, total: 100, autoBackup: true, retentionPeriod: "365", }, }) const [showApiKey, setShowApiKey] = useState(false) const [isSaving, setIsSaving] = useState(false) const [notification, setNotification] = useState<{ type: "success" | "error" | "info"; message: string } | null>(null) const [showPairingWords, setShowPairingWords] = useState(false) // Vérifier si un seul device est connecté au chargement useEffect(() => { if (settings.security.activeDevices === 1) { // Attendre un peu avant d'afficher la modal pour laisser le temps à la page de se charger const timer = setTimeout(() => { setShowAddDeviceModal(true) }, 2000) return () => clearTimeout(timer) } }, [settings.security.activeDevices]) const showNotification = (type: "success" | "error" | "info", message: string) => { setNotification({ type, message }) setTimeout(() => setNotification(null), 3000) } const tabs = [ { id: "profile", name: "Profil", icon: User }, { id: "security", name: "Sécurité", icon: Shield }, { id: "notifications", name: "Notifications", icon: Bell }, { id: "appearance", name: "Apparence", icon: Palette }, { id: "privacy", name: "Confidentialité", icon: Lock }, { id: "storage", name: "Stockage", icon: Database }, { id: "api", name: "API", icon: Key }, ] const handleSave = async () => { setIsSaving(true) // Simuler la sauvegarde await new Promise((resolve) => setTimeout(resolve, 1000)) setIsSaving(false) showNotification("success", "Paramètres sauvegardés avec succès") } const handleExportData = () => { setShowExportConfirmation(true) } const confirmExportData = async () => { setShowExportConfirmation(false) showNotification("info", "Export des données en cours...") // Simuler l'export de toutes les données IndexedDB setTimeout(() => { // Créer un objet simulant les données exportées const exportData = { timestamp: new Date().toISOString(), userData: settings, documents: "Données des documents chiffrées", folders: "Données des dossiers chiffrées", privateKey: "PRIVATE_KEY_ENCRYPTED_DATA", certificates: "Certificats blockchain", chatHistory: "Historique des conversations", preferences: "Préférences utilisateur", warning: "⚠️ Ce fichier contient votre clé privée. Gardez-le en sécurité !", } // Simuler le téléchargement 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 = `docv-export-${new Date().toISOString().split("T")[0]}.json` document.body.appendChild(a) a.click() document.body.removeChild(a) URL.revokeObjectURL(url) showNotification("success", "Export terminé. Fichier téléchargé avec succès.") }, 3000) } const generateApiKey = () => { return "docv_" + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) } const generatePairingWords = () => { const words = ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel"] return Array.from({ length: 4 }, () => words[Math.floor(Math.random() * words.length)]) } const [pairingWords] = useState(generatePairingWords()) const handleAddDevice = () => { setShowAddDeviceModal(false) setSettings((prev) => ({ ...prev, security: { ...prev.security, activeDevices: prev.security.activeDevices + 1, }, })) showNotification("success", "Instructions d'appairage générées. Suivez les étapes sur votre autre appareil.") } const renderProfileTab = () => (
Informations personnelles
{settings.profile.firstName.charAt(0)} {settings.profile.lastName.charAt(0)}

JPG, PNG ou GIF. Max 2MB.

setSettings({ ...settings, profile: { ...settings.profile, firstName: e.target.value }, }) } />
setSettings({ ...settings, profile: { ...settings.profile, lastName: e.target.value }, }) } />
setSettings({ ...settings, profile: { ...settings.profile, email: e.target.value }, }) } />
setSettings({ ...settings, profile: { ...settings.profile, phone: e.target.value }, }) } />
setSettings({ ...settings, profile: { ...settings.profile, position: e.target.value }, }) } />
setSettings({ ...settings, profile: { ...settings.profile, department: e.target.value }, }) } />