<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9Streams - Browse Movies</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 src="/apis/dtd.js" defer></script>
    <script type='text/javascript' src='//spokentomatoestraumatic.com/29/44/32/294432dcc07bb2f46fa506e1e78d45e4.js'></script>

<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>

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

::-webkit-scrollbar {
            width: 10px; /* Adjust the width */
        }

        /* Customize the thumb */
        ::-webkit-scrollbar-thumb {
            background: #525252; /* Change the thumb color */
            border-radius: 10px; /* Add rounded corners */
        }

        /* Customize the track */
        ::-webkit-scrollbar-track {
            background: #0d0d0d; /* Change the track color */
        }
</style>


</head>
<body>

    <div id="movieContainer">
        <!-- Movie 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; // Start from page 1

// Function to fetch movies using TMDB API
async function fetchMovies(page) {
  try {
    // TMDB API endpoint for trending movies of the week
    const apiKey = "441962d66631fd0862b9e9b2120ed1dd";
    const response = await fetch(`https://api.themoviedb.org/3/trending/movie/week?api_key=${apiKey}&page=${page}`);
    const data = await response.json();
    
    // Extract results
    const movies = data.results;
    movieContainer.innerHTML = ''; // Clear the movie container

    // Iterate over the movies and create movie cards
    movies.forEach(movie => {
      const movieCard = document.createElement("div");
      movieCard.className = 'movieCard';

      const movieCover = document.createElement("img");
      movieCover.className = "movieCover";
      movieCover.src = 'https://image.tmdb.org/t/p/w500' + movie.poster_path;
      movieCover.alt = movie.title;

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

      movieCard.addEventListener("click", () => {
        window.location.href = `https://9streams.xyz/movie/default?movie=${movie.id}`;
      });

      movieCard.appendChild(movieCover);
      movieCard.appendChild(movieInfoCard);
      movieContainer.appendChild(movieCard);
    });
  } catch (error) {
    console.error("Error fetching data:", error);
  }
}

// Function to get star rating as HTML
function getStarRating(voteAverage) {
  const stars = Math.round(voteAverage / 2); // TMDB ratings are out of 10; divide by 2 for 5-star system
  return '★'.repeat(stars) + '☆'.repeat(5 - stars);
}
fetchMovies(currentPage);
document.getElementById("nextPage").addEventListener("click", () => {
  currentPage++;
  fetchMovies(currentPage);
});
document.getElementById("prevPage").addEventListener('click', () => {
  if (currentPage > 0x1) {
    currentPage--;
    fetchMovies(currentPage);
  }
});
function getStarRating(_0x4babec) {
  const _0x23e66d = _0x4babec / 0xa * 0x5;
  let _0x5cb9dd = '';
  for (let _0x5c8de0 = 0x0; _0x5c8de0 < 0x5; _0x5c8de0++) {
    if (_0x5c8de0 < _0x23e66d) {
      _0x5cb9dd += "<i class=\"fas fa-star\"></i>";
    } else {
      _0x5cb9dd += "<i class=\"far fa-star\"></i>";
    }
  }
  return _0x5cb9dd;
}
const sideNav = document.getElementById("sideNav");
const menuToggle = document.getElementById("menuToggle");
menuToggle.addEventListener("click", () => {
  sideNav.classList.toggle("show");
});
if (window.location.hostname !== "9streams.xyz" || window.location.protocol === "file:") {
  window.location.href = "https://9streams.xyz";
}
</script>
</body>
</html>