<?php
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/layout.php';

$limit = settingInt('recommendation_limit', 12, 3, 50);
$recommended = getSmartRecommendedSongs($limit);
$neverPlayed = getNeverPlayedSongs(12);
$oldLiked = getOldLikedSongs(12);
$favoriteGenres = getFavoriteGenres(8);
$favoriteArtists = getFavoriteArtists(8);

renderHeader('추천', 'recommend');
?>
<div class="recommend-page">
    <div class="page-title-section">
        <h1 class="page-main-title">나를 위한 추천</h1>
        <p class="page-subtitle">최근 재생, 좋아요, 많이 들은 아티스트와 장르를 기준으로 가볍게 추천합니다.</p>
    </div>

    <?php renderMiniSongSection('최근 취향 기반 추천', $recommended, null); ?>
    <?php renderMiniSongSection('재생한 적 없는 곡', $neverPlayed, 'auto_playlist.php?type=never_played'); ?>
    <?php renderMiniSongSection('오래 안 들은 좋아요 곡', $oldLiked, 'auto_playlist.php?type=old_liked'); ?>

    <section class="home-section">
        <h2 class="section-title">취향 요약</h2>
        <div class="explore-card-grid">
            <?php foreach ($favoriteGenres as $genre): ?>
                <a class="explore-card" href="genre.php?name=<?php echo urlencode($genre['genre']); ?>">
                    <strong><?php echo h($genre['genre']); ?></strong>
                    <span><?php echo number_format($genre['score']); ?>회 재생 기반</span>
                </a>
            <?php endforeach; ?>
            <?php foreach ($favoriteArtists as $artist): ?>
                <a class="explore-card" href="artist.php?name=<?php echo urlencode($artist['artist']); ?>">
                    <strong><?php echo h($artist['artist']); ?></strong>
                    <span><?php echo number_format($artist['score']); ?>회 재생 기반</span>
                </a>
            <?php endforeach; ?>
            <?php if (empty($favoriteGenres) && empty($favoriteArtists)): ?>
                <p class="empty-text">추천 기준으로 삼을 재생 기록이 아직 부족합니다. 랜덤 추천과 최근 추가 곡부터 들어보세요.</p>
            <?php endif; ?>
        </div>
    </section>
</div>
<?php renderFooter(); ?>
