import { initRouter } from './router.js';
import { initNavigation } from './navigation.js';

document.addEventListener('DOMContentLoaded', () => {
    initRouter();
    initNavigation();

    document.getElementById('download-archive').addEventListener('click', (e) => {
        e.preventDefault();
        console.log('Téléchargement de l\'archive');
    });
});

async function loadTemplate(templateName) {
    const response = await fetch(`/templates/${templateName}.html`);
    return await response.text();
}

export async function displayHome() {
    const content = document.getElementById('content');
    content.innerHTML = await loadTemplate('home');
}

export async function displaySources(sources) {
    const content = document.getElementById('content');
    content.innerHTML = await loadTemplate('sources');
    
    const sourcesList = document.getElementById('sourcesList');
    sourcesList.innerHTML = sources.map(source => `
        <li class="source-item">
            <h3>${source.title}</h3>
            <p>${source.description}</p>
            <p class="category">Catégorie: ${source.category}</p>
            <a href="${source.archiveUrl}" target="_blank">Lien archivé</a>
        </li>
    `).join('');
}

export async function displaySuggestionForm() {
    const content = document.getElementById('content');
    content.innerHTML = await loadTemplate('suggest');
    
    document.getElementById('suggestionForm').addEventListener('submit', (e) => {
        e.preventDefault();
        // Logique pour traiter la soumission du formulaire
        console.log('Formulaire de suggestion soumis');
    });
}

export async function displaySearchForm() {
    const content = document.getElementById('content');
    content.innerHTML = await loadTemplate('search');
    
    document.getElementById('searchForm').addEventListener('submit', (e) => {
        e.preventDefault();
        // Logique pour traiter la recherche
        console.log('Recherche soumise');
    });
}