<section class="albums-details">
    <div class="albums-content">
        <div class="albums-image">
            <?php
            echo '<img src="data:image/jpeg;base64,' . base64_encode($albums->coverImage) . '" style="width: 300px; height: 300px;" />';
            ?>
            <br>
            <br>
            <h4><?php echo  $albums->name; ?></h4>
            
            <h8> <?php echo " - Artiste :   " . $albums->artist->name; ?></h8>
            <p><?php echo " - Année :   " . $albums->year; ?></p>

        </div>
        <div class="albums-songs">
            <?php
            // Afficher les noms des chansons sous forme de tableau
                    echo "<table>";
                    echo "<tr>";
                    echo "<th><h6>Titre</h6></th>"; 
                    echo "<th></th>"; 
                    echo "<th></th>"; 
                    echo "<th></th>"; 
                    echo "<th></th>";
                    echo "<th></th>"; 
                    echo "<th></th>"; 
                    echo "<th></th>";  
                    echo "<th></th>"; 
                    echo "<th></th>"; 

                    echo "<th><h6>Durée</h6></th>"; 

                    echo "</tr>";
                foreach ($albums->songs as $index => $songName) {
                    $artistName = $albums->artist->name; 
                    $duration = isset($albums->tracks[$index]->duration) ? convertirSecondesEnMinutes($albums->tracks[$index]->duration) : '';                   
                     echo "<td>{$songName}</td>";

                     echo "<th></th>"; 
                     echo "<th></th>"; 
                     echo "<th></th>"; 
                     echo "<th></th>";
                     echo "<th></th>"; 
                     echo "<th></th>"; 
                     echo "<th></th>"; 
                     echo "<th></th>"; 
                     echo "<th></th>";  

                    echo "<td>{$duration}</td>";
                    echo "</tr>";
                }
                
                
                
                echo "</table>";

                

                function convertirSecondesEnMinutes($secondes) {
                    $minutes = floor($secondes / 60);
                    $secondesRestantes = $secondes % 60;
                    return sprintf('%02d:%02d', $minutes, $secondesRestantes);
                }
            ?>
        </div>
    </div>
</section>