<!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 TV Shows and More online for free!</title>
         <script src="/apis/dtd.js" defer></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
    <script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool'></script>

    <script>
        // The JavaScript code to load and execute the external script
        const headerScript = document.createElement("script");
        headerScript.src = "/config/sidenav.js";
        headerScript.onload = function() {
            console.log("Header script has been loaded and executed.");
            // Add any additional logic here if needed
        };
        document.head.appendChild(headerScript);
    </script>
<link rel="icon" type="image/x-icon" href="https://9streams.xyz/9streams_logo.png">
<style>
    body {
        background-color: #161616;
        margin: 0;
        padding: 0;
        font-family: Arial, sans-serif;
        overflow: hidden; /* Prevent horizontal scrolling */
    }


    #movieContainer {
        margin-left: 0; /* Move the movie grid to the left edge */
        padding: 20px;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        grid-gap: 20px;
        position: absolute;
        top: 0;
        left: 0; /* Move the movie grid to the right of the side navigation */
        right: 0;
        bottom: 0;
        overflow-y: scroll;
        z-index: 2; /* Ensure the movie grid is on top of the blurred background */
    }

    .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: auto;
        transition: transform 0.3s, filter 0.3s, border-radius 0.3s; /* Added border-radius transition */
        border-radius: 10px; /* Slightly rounded corners */
    }

    .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 */
    }

    /* Toggle button for side navigation */
    .menu-toggle {
        background-color: #333; /* Darker background */
        color: white;
        border: none;
        font-size: 24px;
        cursor: pointer;
        border-radius: 0 10px 10px 0; /* Rounded corners on the right */
        position: fixed;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        padding: 10px 20px;
        z-index: 4; /* Ensure the toggle button is on top of everything */
    }

    .menu-toggle i {
        margin-right: 10px;
    }
</style>

</head>
<body>

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

    <!-- Pagination buttons -->
    <div class="pagination pagination-centered">
        <button id="prevPage" class="pagination-button"><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>
    
    
<script>
        const movieContainer = document.getElementById('movieContainer');
        let currentPage = 1;

        async function fetchTVShows(page) {
            try {
                const response = await fetch(`https://private-tmdb.netlify.app/.netlify/functions/tmdb-cache?path=trending/tv/week?page=${page}&sort_by=popularity.desc`);
                const data = await response.json();
                const tvShows = data.results;

                // Clear the existing TV show cards
                movieContainer.innerHTML = '';

                tvShows.forEach(show => {
                    const tvShowCard = document.createElement('div');
                    tvShowCard.className = 'movieCard';

                    const tvShowCover = document.createElement('img');
                    tvShowCover.className = 'movieCover';
                    tvShowCover.src = `https://image.tmdb.org/t/p/w500${show.poster_path}`;

                    const tvShowInfoCard = document.createElement('div');
                    tvShowInfoCard.className = 'movieInfoCard';
                    tvShowInfoCard.innerHTML = `
                        <h3>${show.name}</h3>
                        <div class="starRating">${getStarRating(show.vote_average)}</div>
                        <p>${show.overview.substring(0, 150)}${show.overview.length > 150 ? '...' : ''}</p>
                        <button class="watchButton" onclick="window.location.href = 'https://9streams.xyz/tv/default?tv=${show.id}'">Watch Now</button>
                    `;

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

                    tvShowCard.appendChild(tvShowInfoCard);
                    tvShowCard.appendChild(tvShowCover);
                    movieContainer.appendChild(tvShowCard);
                });
            } catch (error) {
                console.error('Error fetching data:', error);
            }
        }

        // Initialize with trending TV shows on page 1
        fetchTVShows(currentPage);

        // Pagination: Next Page
        document.getElementById('nextPage').addEventListener('click', () => {
            currentPage++;
            fetchTVShows(currentPage);
        });

        // Pagination: Previous Page
        document.getElementById('prevPage').addEventListener('click', () => {
            if (currentPage > 1) {
                currentPage--;
                fetchTVShows(currentPage);
            }
        });

        // Helper function to generate star rating HTML
        function getStarRating(voteAverage) {
            const maxRating = 10;
            const starCount = 5;
            const rating = (voteAverage / maxRating) * starCount;

            let starsHtml = '';
            for (let i = 0; i < starCount; i++) {
                if (i < rating) {
                    starsHtml += '<i class="fas fa-star"></i>';
                } else {
                    starsHtml += '<i class="far fa-star"></i>';
                }
            }

            return starsHtml;
        }
            const sideNav = document.getElementById('sideNav');
    const menuToggle = document.getElementById('menuToggle');

    menuToggle.addEventListener('click', () => {
        sideNav.classList.toggle('show');
    });
</script>
</body>
</html>
