<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>NOTFLIX TV</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="//content.jwplatform.com/libraries/SAHhwvZq.js"></script>
  <script>document.addEventListener('contextmenu', function(event) {event.preventDefault();});</script>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div id="wrapper">
    <div id="jwplayerDiv"></div>
    <div class="right-side">
      <div class="playlist-container">
        <ul id="playlistList"></ul>
      </div>
      <div class="iframe-container">
        <iframe src="chatbox.php" frameborder="0" scrolling="no" height="100%" width="100%"></iframe>
      </div>
    </div>
  </div>
  <script>
    fetch('channels.php')
      .then(response => response.json())
      .then(data => {
        const playlistList = document.getElementById('playlistList');
        data.forEach((channel, index) => {
          const listItem = document.createElement('LI');
          const link = document.createElement('A');
          link.href = '#';
          link.textContent = channel.name;
          link.onclick = () => playStream(channel, link);
          listItem.appendChild(link);
          playlistList.appendChild(listItem);
        });
        playStream(data[0], document.querySelectorAll('#playlistList a')[0]);
      });

    function playStream(channel, element) {
  const playerSetup = {
    file: channel.file,
    autostart: true,
    stretching: "",
    width: "100%",
    type: channel.type || 'hls', // Default to HLS
    drm: channel.drm
  };

  if (channel.type === 'hls') {
    playerSetup.hlsjsConfig = {
      debug: false
    };
  }

  jwplayer("jwplayerDiv").setup(playerSetup);

  document.querySelectorAll('#playlistList a').forEach(a => a.classList.remove('playing'));
  element.classList.add('playing');
}
  </script>
</body>
</html>