<!doctype html>
<html lang="pl">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>PREMIUMSMART TV - Zaloguj</title>
    <style>
      body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        background-color: #141414;
        color: #bfff00;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
      }

      .login-box {
        background-color: #333;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0px 0px 15px #bfff00, 0px 0px 30px #bfff00, 0px 0px 45px #bfff00;
        max-width: 350px;
        width: 100%;
        text-align: center;
        animation: neon-blink 1.5s ease-in-out infinite alternate;
      }

      @keyframes neon-blink {
        0% {
          box-shadow: 0px 0px 5px #bfff00, 0px 0px 10px #bfff00;
        }
        100% {
          box-shadow: 0px 0px 15px #bfff00, 0px 0px 30px #bfff00, 0px 0px 45px #bfff00;
        }
      }

      .login-box input {
        width: 100%;
        padding: 12px;
        margin: 10px 0;
        border: 2px solid #333;
        border-radius: 5px;
        color: #000;
        background-color: #fff;
        box-sizing: border-box;
      }

      .login-box button {
        background-color: #bfff00;
        border: none;
        padding: 12px;
        width: 100%;
        font-size: 16px;
        cursor: pointer;
        border-radius: 5px;
        margin-top: 10px;
      }

      .login-box button:hover {
        background-color: #99cc00;
      }

      .error {
        color: red;
        margin-top: 10px;
      }
    </style>
    <!-- Dołączenie auth.js -->
    <script src="js/auth.js"></script>
    <script>
      document.addEventListener("DOMContentLoaded", () => {
        // Jeśli użytkownik jest już zalogowany, przekieruj go do select.html
        if (isSessionValid()) {
          window.location.href = 'select.html';
        }

        // Obsługa formularza logowania
        document.getElementById('login-form').addEventListener('submit', (e) => {
          e.preventDefault();
          const enteredPassword = document.getElementById('password').value.trim();

          if (enteredPassword === mainPassword) {
            const currentTime = Date.now();
            localStorage.setItem('authenticated', 'true');
            localStorage.setItem('loginTime', currentTime.toString());
            localStorage.removeItem('vip'); // Nie VIP
            localStorage.removeItem('vipUsername');
            localStorage.setItem('userPassword', enteredPassword);
            window.location.href = 'select.html'; // Przekierowanie do wyboru opcji
          } else if (vipCredentials.hasOwnProperty(enteredPassword)) {
            const currentTime = Date.now();
            const username = vipCredentials[enteredPassword];
            localStorage.setItem('authenticated', 'true');
            localStorage.setItem('vip', 'true');
            localStorage.setItem('vipUsername', username);
            localStorage.setItem('loginTime', currentTime.toString());
            localStorage.setItem('userPassword', enteredPassword);
            window.location.href = 'select.html'; // Przekierowanie do wyboru opcji
          } else {
            document.getElementById('error-message').style.display = 'block';
          }
        });
      });
    </script>
  </head>
  <body>
    <!-- Sekcja logowania -->
    <div class="login-box" id="login-box">
      <h2>PREMIUMSMART TV</h2>
      <div id="error-message" class="error" style="display: none;">Złe hasło. Spróbuj ponownie.</div>
      <form id="login-form">
        <input type="password" id="password" placeholder="Wprowadź hasło" required />
        <button type="submit">Zaloguj</button>
      </form>
    </div>
  </body>
</html>
