<?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';

$genre = normalizeMetaParam($_GET['name'] ?? '');
$label = genreName($genre);
$params = [];
$where = 's.is_missing = 0 AND ' . metaWhereSql('s.genre', ':genre', $genre === '알 수 없는 장르' ? '' : $genre, $params);
$songs = fetchSongs($where, $params, 's.artist ASC, s.album ASC, s.track_no ASC, s.title ASC');

renderHeader($label, 'genres');
?>
<div class="music-list-page">
    <div class="page-title-section">
        <h1 class="page-main-title"><?php echo h($label); ?></h1>
        <p class="page-subtitle"><?php echo number_format(count($songs)); ?>곡이 이 장르에 포함되어 있습니다.</p>
    </div>
    <?php renderSongList($songs); ?>
</div>
<?php renderFooter(); ?>
