// Recommendations and Latest Releases module // Load personalized recommendations async function loadRecommendations() { const container = document.getElementById('recommendationsList'); const section = document.getElementById('recommendationsSection'); if (!container) return; try { container.innerHTML = '
Analyse de vos téléchargements...
'; const response = await fetch(`${API_BASE}/recommendations?limit=12`); const data = await response.json(); console.log('Recommendations response:', data); if (data.recommendations && data.recommendations.length > 0) { container.innerHTML = ``; } else { container.innerHTML = `

Aucune recommandation disponible pour le moment.

Soit l'API MyAnimeList est inaccessible, soit vous n'avez pas encore de téléchargements.

`; } section.style.display = 'block'; } catch (error) { console.error('Error loading recommendations:', error); container.innerHTML = `

Erreur lors du chargement des recommandations.

${error.message}

`; section.style.display = 'block'; } } // Load latest releases async function loadLatestReleases() { const container = document.getElementById('releasesList'); const section = document.getElementById('releasesSection'); if (!container) return; try { container.innerHTML = '
Chargement des dernières sorties...
'; const response = await fetch(`${API_BASE}/releases/latest?limit=12`); const data = await response.json(); console.log('Releases response:', data); if (data.releases && data.releases.length > 0) { container.innerHTML = ``; } else { container.innerHTML = `

Aucune sortie disponible pour le moment.

L'API MyAnimeList pourrait être temporairement inaccessible.

`; } section.style.display = 'block'; } catch (error) { console.error('Error loading releases:', error); container.innerHTML = `

Erreur lors du chargement des sorties.

${error.message}

`; section.style.display = 'block'; } } // Load all home content async function loadHomeContent() { console.log('loadHomeContent() called'); const loading = document.getElementById('homeLoading'); const recommendationsSection = document.getElementById('recommendationsSection'); const releasesSection = document.getElementById('releasesSection'); console.log('Elements found:', { loading: !!loading, recommendationsSection: !!recommendationsSection, releasesSection: !!releasesSection }); if (loading) loading.style.display = 'block'; if (recommendationsSection) recommendationsSection.style.display = 'none'; if (releasesSection) releasesSection.style.display = 'none'; try { // Load both sections in parallel console.log('Loading recommendations and releases...'); await Promise.all([ loadRecommendations(), loadLatestReleases() ]); console.log('Home content loaded successfully'); // Show sections if they have content if (recommendationsSection) recommendationsSection.style.display = 'block'; if (releasesSection) releasesSection.style.display = 'block'; } catch (error) { console.error('Error loading home content:', error); if (loading) { loading.innerHTML = 'Erreur lors du chargement. Consultez la console pour plus de détails.'; } } finally { if (loading) loading.style.display = 'none'; } } // Render recommendation card (horizontal compact) function renderRecommendationCard(anime) { const images = anime.images || {}; const imageUrl = images.jpg?.image_url || images.webp?.image_url || ''; const genres = anime.genres || []; const score = anime.score || 0; const reason = anime.recommendation_reason || 'Recommandé'; return `
${reason ? `
${escapeHtml(reason)}
` : ''}
${escapeHtml(anime.title)}
${score > 0 ? `
${score.toFixed(1)}
` : ''}
${imageUrl ? `` : ''}
${genres.slice(0, 3).map(g => `${escapeHtml(g)}`).join('')}
${anime.episodes ? ` ${anime.episodes} ep` : ''} ${anime.episodes && anime.status ? ' • ' : ''} ${anime.status ? translateStatus(anime.status) : ''}
${anime.synopsis ? `
Synopsis

${escapeHtml(anime.synopsis.substring(0, 150))}${anime.synopsis.length > 150 ? '...' : ''}

` : ''}
`; } // Render release card (horizontal compact) function renderReleaseCard(anime) { const images = anime.images || {}; const imageUrl = images.jpg?.image_url || images.webp?.image_url || ''; const genres = anime.genres || []; const score = anime.score || 0; const releaseType = anime.release_type || 'Nouveau'; return `
${escapeHtml(releaseType)}
${escapeHtml(anime.title)}
${score > 0 ? `
${score.toFixed(1)}
` : ''}
${imageUrl ? `` : ''}
${genres.slice(0, 3).map(g => `${escapeHtml(g)}`).join('')}
${anime.episodes ? ` ${anime.episodes} ep` : ''} ${anime.episodes && anime.status ? ' • ' : ''} ${anime.status ? translateStatus(anime.status) : ''}
${anime.synopsis ? `
Synopsis

${escapeHtml(anime.synopsis.substring(0, 150))}${anime.synopsis.length > 150 ? '...' : ''}

` : ''}
`; } // Get rating color based on score function getRatingColor(score) { if (score >= 9) return '#ffd700'; if (score >= 8) return '#2d936c'; if (score >= 7) return '#FF9F1C'; if (score >= 6) return '#f4a261'; return '#888888'; } // Search anime on providers (redirects to anime tab) function searchAnimeOnProviders(title) { // Switch to anime tab switchTab('anime'); // Fill search input const searchInput = document.getElementById('animeSearchInput'); if (searchInput) { searchInput.value = title; // Trigger search setTimeout(() => { if (typeof handleAnimeSearch === 'function') { handleAnimeSearch(); } }, 300); } }