"use client" import { useState, useEffect, useCallback } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { FileText, Folder, Users, Activity, TrendingUp, Clock, Shield, AlertCircle, CheckCircle, Download, Upload, Search, Plus, MoreHorizontal, Edit, Share2, TestTube, Zap, HardDrive, X, FolderPlus, XCircle, Info, } from "@/lib/icons" import MessageBus from "@/lib/4nk/MessageBus" import Link from "next/link" import Chat from "@/components/4nk/Chat" import UserStore from "@/lib/4nk/UserStore" import EventBus from "@/lib/4nk/EventBus" import { iframeUrl } from "../page" import Iframe from "@/components/4nk/Iframe" type FolderType = string; export default function DashboardPage() { const [notification, setNotification] = useState<{ type: "success" | "error" | "info"; message: string } | null>(null) // 4NK Integration states const [isConnected, setIsConnected] = useState(false) const [showAuthModal, setShowAuthModal] = useState(false) const [processes, setProcesses] = useState(null) const [myProcesses, setMyProcesses] = useState([]) const [userPairingId, setUserPairingId] = useState(null) const [isModalOpen, setIsModalOpen] = useState(false); const [menuOpen, setMenuOpen] = useState(false); const [folderType, setFolderType] = useState(null); const [stats, setStats] = useState({ totalDocuments: 0, totalFolders: 0, totalUsers: 0, storageUsed: 0, storageLimit: 100, recentActivity: 0, // Nouveaux indicateurs permanentStorage: 0, permanentStorageLimit: 1000, // 1 To en Go temporaryStorage: 0, temporaryStorageLimit: 100, // 100 Go newFoldersThisMonth: 0, newFoldersLimit: 75, tokensUsed: 0, tokensTotal: 1000, }) const [recentDocuments, setRecentDocuments] = useState([]) const [recentActivity, setRecentActivity] = useState([]) const [notifications, setNotifications] = useState([]) useEffect(() => { // Simuler le chargement des données const mockMode = true if (mockMode) { setStats({ totalDocuments: 1247, totalFolders: 89, totalUsers: 12, storageUsed: 67.3, storageLimit: 100, recentActivity: 24, // Nouveaux indicateurs avec données réalistes permanentStorage: 673, // 673 Go utilisés sur 1000 Go permanentStorageLimit: 1000, temporaryStorage: 45, // 45 Go utilisés sur 100 Go temporaryStorageLimit: 100, newFoldersThisMonth: 23, // 23 nouveaux dossiers ce mois newFoldersLimit: 75, tokensUsed: 673, // Environ 67% des jetons utilisés tokensTotal: 1000, }) setRecentDocuments([ { id: "doc_001", name: "Contrat_Client_ABC_2024.pdf", type: "PDF", size: "2.4 MB", modifiedAt: "Il y a 2 heures", modifiedBy: "Marie Dubois", status: "Signé", folder: "Général", }, { id: "doc_002", name: "Contrat_Fournisseur_XYZ.pdf", type: "PDF", size: "1.8 MB", modifiedAt: "Il y a 4 heures", modifiedBy: "Jean Martin", status: "En révision", folder: "Général", }, { id: "doc_003", name: "Avenant_Contrat_123.docx", type: "Word", size: "892 KB", modifiedAt: "Il y a 2 jours", modifiedBy: "Pierre Durand", status: "Brouillon", folder: "Général", }, ]) setRecentActivity([ { id: "act_001", type: "upload", user: "Marie Dubois", action: "a téléchargé", target: "Contrat_Client_ABC_2024.pdf", time: "Il y a 2 heures", icon: Upload, color: "text-green-600", }, { id: "act_002", type: "edit", user: "Jean Martin", action: "a modifié", target: "Contrat_Fournisseur_XYZ.pdf", time: "Il y a 4 heures", icon: Edit, color: "text-blue-600", }, { id: "act_003", type: "share", user: "Sophie Laurent", action: "a partagé", target: "Contrat_Client_ABC_2024.pdf", time: "Hier", icon: Share2, color: "text-purple-600", }, { id: "act_004", type: "create", user: "Pierre Durand", action: "a créé le dossier", target: "Dossier Général", time: "Il y a 2 jours", icon: Folder, color: "text-orange-600", }, ]) setNotifications([ { id: "notif_001", type: "success", title: "Document signé", message: "Le contrat ABC a été signé par toutes les parties", time: "Il y a 1 heure", icon: CheckCircle, color: "text-green-600", bgColor: "bg-green-50", }, { id: "notif_002", type: "warning", title: "Stockage temporaire élevé", message: "45 Go utilisés sur 100 Go de stockage temporaire ce mois", time: "Il y a 2 heures", icon: AlertCircle, color: "text-orange-600", bgColor: "bg-orange-50", }, { id: "notif_003", type: "info", title: "Nouveau contrat", message: "Un nouveau document a été ajouté au dossier Général", time: "Hier", icon: FileText, color: "text-blue-600", bgColor: "bg-blue-50", }, ]) } }, []) const getFileIcon = (type: string) => { switch (type.toLowerCase()) { case "pdf": return "📄" case "excel": return "📊" case "powerpoint": return "📈" case "word": return "📝" default: return "📄" } } const getStatusColor = (status: string) => { switch (status.toLowerCase()) { case "signé": case "finalisé": case "payée": return "bg-green-100 text-green-800" case "en révision": return "bg-orange-100 text-orange-800" case "brouillon": return "bg-gray-100 text-gray-800" default: return "bg-blue-100 text-blue-800" } } // 4NK Integration useEffects useEffect(() => { const userStore = UserStore.getInstance(); const connected = userStore.isConnected(); const pairingId = userStore.getUserPairingId(); console.log('Initialisation 4NK:', { connected, pairingId }); setIsConnected(connected); setUserPairingId(pairingId); }, []); useEffect(() => { const handleConnectionFlow = async () => { if (!isConnected) return; const userStore = UserStore.getInstance(); const messageBus = MessageBus.getInstance(iframeUrl); try { await messageBus.isReady(); let pairingId = userStore.getUserPairingId(); // 1️⃣ Créer le pairing si non existant if (!pairingId || pairingId === 'undefined' || pairingId === 'null') { // We may have a pairing id but the value is not in cache for some reason pairingId = await messageBus.getUserPairingId(); if (pairingId) { userStore.pair(pairingId); setUserPairingId(pairingId); } else { console.log("🚀 No pairing found — creating new pairing..."); pairingId = await messageBus.createUserPairing(); console.log("✅ Pairing created:", pairingId); userStore.pair(pairingId); setUserPairingId(pairingId); } } else { console.log("🔗 Already paired with ID:", pairingId); } // 2️⃣ Charger les processes const processes = await messageBus.getProcesses(); setProcesses(processes); // 3️⃣ Charger les myProcesses const myProcesses = await messageBus.getMyProcesses(); setMyProcesses(myProcesses); } catch (err) { console.error("❌ Error during pairing or process loading:", err); } }; handleConnectionFlow(); }, [isConnected, iframeUrl]); const handleOpenModal = (type: FolderType) => { setFolderType(type); setIsModalOpen(true); setMenuOpen(false); }; const handleCloseModal = () => { setIsModalOpen(false); setFolderType(null); }; // Notification system const showNotification = (type: "success" | "error" | "info", message: string) => { setNotification({ type, message }) setTimeout(() => setNotification(null), 3000) } // 4NK handlers return (
{/* Notification */} {notification && (
{notification.type === "success" && } {notification.type === "error" && } {notification.type === "info" && } {notification.message}
)} {/* En-tête */}

My work

Vue d'ensemble de votre espace documentaire sécurisé

{/* Statistiques principales */}
{/* SUPPRIMER les cartes Documents, Dossiers, Collaborateurs */} {/* Conserver uniquement les autres indicateurs utiles (ex : Jetons utilisés, stockage, etc.) */}
{/* Messages intégrés */}
{/* Nouveaux indicateurs de stockage */}
Stockage permanent
{stats.permanentStorage} Go

{stats.permanentStorage} Go / {stats.permanentStorageLimit} Go (1 To)

Stockage temporaire
{stats.temporaryStorage} Go
80 ? "bg-red-600 dark:bg-red-500" : stats.temporaryStorage > 60 ? "bg-orange-600 dark:bg-orange-500" : "bg-green-600 dark:bg-green-500" }`} style={{ width: `${(stats.temporaryStorage / stats.temporaryStorageLimit) * 100}%` }} >

{stats.temporaryStorage} Go / {stats.temporaryStorageLimit} Go ce mois

Nouveaux dossiers
{stats.newFoldersThisMonth}

{stats.newFoldersThisMonth} / {stats.newFoldersLimit} ce mois

{/* Sécurité */} Statut de sécurité

Sécurité optimale

Tous vos documents sont chiffrés et sécurisés par la technologie 4NK

Chiffrement bout en bout

Authentification 4NK

Audit complet

{/* 4NK Iframe - only show when connected */} {isConnected &&