<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Redirecting...</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
  body {
    background: linear-gradient(to right, #0d6efd, #6c63ff);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Segoe UI', sans-serif;
    margin: 0;
  }
  .redirect-card {
    background-color: #fff;
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    max-width: 400px;
    width: 90%;
  }
  .redirect-card h1 {
    font-size: 22px;
    margin-bottom: 20px;
    color: #0d6efd;
  }
  .spinner-border {
    width: 3rem;
    height: 3rem;
    margin-bottom: 15px;
  }
  .progress {
    height: 10px;
    border-radius: 5px;
    margin-top: 20px;
  }
  .redirect-link {
    color: #0d6efd;
    text-decoration: none;
    font-weight: 500;
  }
  @media(max-width: 500px) {
    .redirect-card h1 { font-size: 18px; }
    .spinner-border { width: 2.5rem; height: 2.5rem; }
  }
</style>
</head>
<body>
<div class="redirect-card">
  <div class="spinner-border text-primary" role="status"></div>
  <h1>Redirecting you...</h1>
  <p id="countdown-text">You will be redirected in <span id="timer">5</span> seconds</p>
  <div class="progress">
    <div id="progress-bar" class="progress-bar bg-primary" role="progressbar" style="width: 0%"></div>
  </div>
  <p class="mt-3">If not redirected, <a href="<%= original_url %>" class="redirect-link">click here</a>.</p>
</div>

<script>
  const originalUrl = "<%= original_url %>";
  let timer = 5;
  const timerEl = document.getElementById('timer');
  const progressBar = document.getElementById('progress-bar');

  const interval = setInterval(() => {
    timer--;
    timerEl.textContent = timer;
    progressBar.style.width = ((5 - timer)/5)*100 + "%";
    if(timer <= 0) {
      clearInterval(interval);
      window.location.href = originalUrl;
    }
  }, 1000);
</script>
</body>
</html>
