<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9Streams.xyz - Stream Anime and More online for free!</title>
    <!-- Add Font Awesome CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
<script type='text/javascript' src='//spokentomatoestraumatic.com/29/44/32/294432dcc07bb2f46fa506e1e78d45e4.js'></script>
         <script src="/apis/dtd.js" defer></script>
        <link rel="icon" type="image/x-icon" href="https://9streams.xyz/9streams_logo.png">
<script>
    const headerScript = document.createElement("script");
    headerScript.src = "https://9streams.xyz/config/sidenav.js";
    headerScript.async = true;
    headerScript.onload = function() {
        console.log("Header script has been loaded and executed.");
    };
    document.head.appendChild(headerScript);
</script>
    <style>
        /* Your CSS styles here */
        body {
            background-color: #161616;
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            overflow-x: hidden; /* Prevent horizontal scrolling */
        }

        #movieContainer {
            margin: 0; /* Remove outer margin */
            padding: 20px; /* Add padding for spacing */
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); /* Adjusted for responsiveness */
            grid-gap: 10px; /* Reduced gap between posters */
            position: relative;
            overflow-y: auto; /* Allow vertical scrolling */
            height: calc(100vh - 70px); /* Cover the entire viewport height minus pagination height */
            z-index: 1; /* Ensure the movie grid is behind the pagination buttons */
        }

        .movieCard {
            position: relative;
            cursor: pointer;
            z-index: 2;
            transition: opacity 0.3s;
        }

        .movieCard:hover {
            opacity: 0.9; /* Slight transparency on hover */
        }

        /* Movie poster styles */
        .movieCover {
            width: 100%;
            height: 300px; /* Set a fixed height for uniformity */
            object-fit: cover; /* Maintain aspect ratio and cover the container */
            border-radius: 10px; /* Slightly rounded corners */
            transition: transform 0.3s, filter 0.3s, border-radius 0.3s; /* Retain existing transitions */
        }

        .movieCard:hover .movieCover {
            transform: scale(1.1);
            filter: blur(5px);
        }

        /* Add movie info card */
        .movieInfoCard {
            position: absolute;
            background-color: #131313;
            color: white;
            max-width: 300px;
            padding: 10px;
            border-radius: 5px;
            pointer-events: none;
            display: none;
            top: 0;
            left: -320px;
            transition: opacity 0.3s, left 0.3s;
            z-index: 1;
        }

        .movieCard:hover .movieInfoCard {
            display: block;
            opacity: 1;
            left: -10px;
        }

        .movieInfoCard h3 {
            font-size: 18px;
            margin: 0;
            margin-bottom: 5px;
        }

        .movieInfoCard p {
            font-size: 14px;
            margin: 0;
            max-height: 150px; /* Limit the description height */
            overflow: hidden;
        }

        /* Star rating */
        .starRating {
            color: #f1c40f;
            font-size: 18px;
        }

        /* "Watch Now" button */
        .watchButton {
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 20px;
            padding: 5px 15px;
            text-align: center;
            cursor: pointer;
            transition: 0.3s;
            margin: 10px auto; /* Center the button horizontally */
            display: block; /* Make the button a block element */
        }

        .watchButton:hover {
            background-color: #0056b3;
        }

        /* Pagination buttons */
        .pagination {
            text-align: center;
            position: fixed; /* Fixed position at the bottom */
            bottom: 20px; /* Adjust the distance from the bottom */
            left: 0;
            right: 0;
            background-color: rgba(34, 34, 34, 0.8); /* Blurred background */
            backdrop-filter: blur(10px); /* Add blur effect to background */
            padding: 10px 0; /* Adjust padding as needed */
            z-index: 3; /* Ensure buttons are on top of other content */
        }

        .pagination button {
            background-color: transparent;
            color: white;
            border: none;
            font-size: 18px; /* Decrease button font size */
            cursor: pointer;
            margin: 0 5px; /* Adjust margin for smaller buttons */
            border-radius: 5px; /* Slightly rounded corners */
            padding: 5px 10px; /* Adjust padding for smaller buttons */
            position: relative;
            z-index: 3; /* Ensure buttons are on top of movie posters */
        }

        .pagination button:hover {
            background-color: #444;
        }

        /* Center the pagination buttons */
        .pagination-centered {
            display: flex;
            justify-content: center;
            align-items: center;
        }

        /* Pagination button text */
        .pagination-text {
            color: white;
            font-size: 14px; /* Decrease button text font size */
            margin: 0 5px; /* Adjust margin for smaller buttons */
        }

        /* Loading spinner */
        .spinner-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.8); /* Dark semi-transparent background */
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 1000; /* Ensure it's on top of all other content */
            transition: opacity 0.3s ease;
        }

        .spinner {
            border: 4px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top: 4px solid #ffffff;
            width: 60px; /* Larger size for better visibility */
            height: 60px; /* Larger size for better visibility */
            animation: spin 2s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>

    <!-- Toggle button for side navigation -->
    <button class="menu-toggle" id="menuToggle"><i class="fas fa-bars"></i></button>

    <div id="movieContainer">
        <!-- Anime covers and info will be dynamically added here -->
    </div>

    <!-- Pagination buttons -->
    <div class="pagination pagination-centered">
        <button id="prevPage" class="pagination-button" disabled><i class="fas fa-chevron-left"></i> Previous Page</button>
        <button id="nextPage" class="pagination-button">Next Page <i class="fas fa-chevron-right"></i></button>
    </div>
    
    <div class="spinner-overlay" id="loadingOverlay" style="display: none;">
        <div class="spinner"></div>
    </div>

<script>
const movieContainer = document.getElementById('movieContainer');
const loadingOverlay = document.getElementById('loadingOverlay');
let currentPage = 1;

async function fetchTopAnime(pageNumber) {
    try {
        // Show loading overlay
        loadingOverlay.style.display = 'flex';

        // Fetch the data from the API
        const response = await fetch(`https://consumet-anime-beta.vercel.app/meta/anilist/trending?page=${pageNumber}&perPage=25`);
        const data = await response.json();

        // Clear the existing anime cards
        movieContainer.innerHTML = '';

        data.results.forEach(anime => {
            const animeCard = document.createElement('div');
            animeCard.className = 'movieCard';

            const animeCover = document.createElement('img');
            animeCover.className = 'movieCover';
            animeCover.src = anime.image;

            const animeInfoCard = document.createElement('div');
            animeInfoCard.className = 'movieInfoCard';
            animeInfoCard.innerHTML = `
                <h3>${anime.title.english || anime.title.romaji}</h3>
                <p>${anime.genres.join(', ')}</p> <!-- Display genres -->
            `;

            // Add click event to anime card
            animeCard.addEventListener('click', () => {
                window.location.href = `https://9streams.xyz/anime/default?anime=${anime.id}`;
            });

            animeCard.appendChild(animeCover);
            animeCard.appendChild(animeInfoCard);
            movieContainer.appendChild(animeCard);
        });

        currentPage = pageNumber;

        // Update pagination button states
        document.getElementById('prevPage').disabled = currentPage === 1;
        document.getElementById('nextPage').disabled = data.results.length < 25; // Adjusted to 25 (or perPage)

    } catch (error) {
        console.error('Error fetching anime data:', error);
    } finally {
        // Hide loading overlay
        loadingOverlay.style.display = 'none';
    }
}

// Load the first page initially
fetchTopAnime(currentPage);

// Event listeners for pagination buttons
document.getElementById('prevPage').addEventListener('click', () => {
    if (currentPage > 1) {
        fetchTopAnime(currentPage - 1);
    }
});

document.getElementById('nextPage').addEventListener('click', () => {
    fetchTopAnime(currentPage + 1);
});
</script>
</body>
</html>
