'use client';
import React, { useContext } from 'react';
import OfflineContext from '@/context/OfflineContext';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faDatabase, faSync, faExclamationCircle } from '@fortawesome/free-solid-svg-icons';
/**
* OfflineSyncDetails - Detailed view of sync status per table
* Shows pending changes and last sync time for each data type
*/
export default function OfflineSyncDetails() {
const { offlineMode } = useContext(OfflineContext);
const { syncProgress, isDatabaseInitialized } = offlineMode;
if (!isDatabaseInitialized) {
return (
Base de données non initialisée
);
}
if (!syncProgress.tables || syncProgress.tables.length === 0) {
return (
Aucune donnée de synchronisation disponible
);
}
// Format timestamp
const formatTime = (timestamp: number) => {
if (!timestamp) return 'Jamais';
const date = new Date(timestamp);
return date.toLocaleString('fr-FR', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
};
// Get friendly name for table
const getTableName = (table: string): string => {
const names: { [key: string]: string } = {
'erit_books': 'Livres',
'book_chapters': 'Chapitres',
'book_chapter_content': 'Contenu des chapitres',
'book_characters': 'Personnages',
'book_world': 'Monde',
'book_world_elements': 'Éléments du monde',
'ai_conversations': 'Conversations IA',
'ai_messages_history': 'Messages IA',
'book_guide_line': 'Lignes directrices',
'book_plot_points': 'Points de l\'intrigue',
'book_incidents': 'Incidents'
};
return names[table] || table;
};
return (
État de synchronisation
{syncProgress.tables.map((tableStatus) => {
const hasPending = tableStatus.pending > 0;
return (
{getTableName(tableStatus.table)}
Dernière sync: {formatTime(tableStatus.lastSync)}
{hasPending && (
{tableStatus.pending} en attente
)}
{!hasPending && tableStatus.lastSync > 0 && (
✓ Synchronisé
)}
);
})}
{/* Summary */}
Total: {syncProgress.pendingChanges} changement(s) en attente
);
}