<?php

require_once "dbconnection.php";



$announcementText = "📢 No announcements available.";

$sql = "SELECT title, message FROM announcements 

        WHERE DATE(created_at) + INTERVAL days_to_display DAY >= CURDATE()

        ORDER BY id DESC";



$stmt = $con->prepare($sql);

$stmt->execute();

$stmt->bind_result($title, $message);



$items = [];

while ($stmt->fetch()) {

  $safeTitle = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');

  $safeMessage = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');

  $items[] = "<span class='ticker-tag'>NEW</span> <strong>{$safeTitle}</strong>: {$safeMessage}";

}

$stmt->close();



if (!empty($items)) {

  $announcementText = implode(" &nbsp;&nbsp;&nbsp; • &nbsp;&nbsp;&nbsp; ", $items);

}

?>



<!-- Page loader overlay -->

<div id="page-loader">

  <div class="pl-logo">

    <?php echo isset($school_name) ? htmlspecialchars($school_name) : 'Loading...'; ?>

  </div>

  <div class="pl-bar-track">

    <div class="pl-bar-fill"></div>

  </div>

</div>



<style>

  :root {

    --std-primary: #0ea5e9;

    /* Sky Blue */

    --std-dark: #1e3a8a;

    /* Royal Blue */

    --std-glass: rgba(255, 255, 255, 0.85);

    --accent-blue: #4f46e5;

  }





  /* 2026 Student Floating Navbar */

  .main-header.navbar {

    border-radius: 20px !important;

    border: 1px solid rgba(255, 255, 255, 0.4) !important;

    background: var(--std-glass) !important;

    backdrop-filter: blur(15px);

    -webkit-backdrop-filter: blur(15px);

    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);

    padding: 0.6rem 1.2rem;

  }



  /* Floating Announcement Capsule */

  .announcement-bar {

    margin: 0 20px 15px 20px;

    background: linear-gradient(90deg, var(--std-dark), var(--std-primary));

    color: #fff;

    padding: 8px 20px;

    border-radius: 50px;

    font-size: 0.9rem;

    display: flex;

    align-items: center;

    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);

    overflow: hidden;

    position: relative;

  }



  .announcement-icon {

    margin-right: 15px;

    animation: bell-shake 2s infinite;

  }



  @keyframes bell-shake {



    0%,

    100% {

      transform: rotate(0);

    }



    10%,

    30% {

      transform: rotate(15deg);

    }



    20%,

    40% {

      transform: rotate(-15deg);

    }



    50% {

      transform: rotate(0);

    }

  }



  .ticker-tag {

    background: rgba(255, 255, 255, 0.2);

    padding: 2px 8px;

    border-radius: 6px;

    font-size: 0.7rem;

    margin-right: 8px;

    border: 1px solid rgba(255, 255, 255, 0.3);

  }



  .announcement-track {

    display: inline-block;

    white-space: nowrap;

    padding-left: 100%;

    animation: marquee 40s linear infinite;

  }



  @keyframes marquee {

    0% {

      transform: translateX(0);

    }



    100% {

      transform: translateX(-100%);

    }

  }



  /* Search & Profile Refinements */

  .std-search {

    background: rgba(0, 0, 0, 0.04);

    border-radius: 12px;

    border: 1px solid transparent;

    transition: 0.3s;

    padding: 5px 15px;

  }



  .std-search:focus-within {

    background: #fff;

    border-color: var(--std-primary);

    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1);

  }



  .dropdown-menu-lg {

    border-radius: 20px !important;

    border: none !important;

    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1) !important;

    padding: 10px !important;

    margin-top: 15px !important;

  }



  .dropdown-item {

    border-radius: 12px;

    padding: 12px 15px;

    transition: 0.2s;

  }



  .dropdown-item:hover {

    background: #f0f9ff;

    color: var(--std-primary);

    transform: translateX(5px);

  }



  .announcement-close {

    background: rgba(0, 0, 0, 0.1);

    width: 24px;

    height: 24px;

    border-radius: 50%;

    display: flex;

    align-items: center;

    justify-content: center;

    margin-left: 15px;

    cursor: pointer;

    transition: 0.3s;

  }



  .announcement-close:hover {

    background: rgba(255, 255, 255, 0.2);

  }



  /* Custom Loader 2026 */

  #loader {

    background: rgba(255, 255, 255, 0.9);

    backdrop-filter: blur(8px);

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

  }



  .spinner {

    width: 40px;

    height: 40px;

    border: 3px solid #f3f3f3;

    border-top: 3px solid var(--accent-blue);

    border-radius: 50%;

    animation: spin 1s linear infinite;

  }



  @keyframes spin {

    0% {

      transform: rotate(0deg);

    }



    100% {

      transform: rotate(360deg);

    }

  }

</style>



<nav class="main-header navbar navbar-expand">

  <ul class="navbar-nav">

    <li class="nav-item">

      <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-stream"></i></a>

    </li>

    <li class="nav-item d-none d-sm-inline-block">

      <a href="#" class="nav-link font-weight-bold" style="color: var(--std-dark);">Dashboard</a>

    </li>

  </ul>



  <form class="form-inline ml-3 d-none d-md-block" onsubmit="return false;" style="position:relative;">

    <div class="std-search d-flex align-items-center">

      <i class="fas fa-search text-muted mr-2"></i>

      <input type="search" id="navSearchStd" placeholder="Search grades or courses..." autocomplete="off"

        style="border:none; background:transparent; outline:none; font-size: 0.85rem;">

    </div>

    <div id="navSearchResultsStd" class="dropdown-menu dropdown-menu-lg"

      style="display:none; position:absolute; top:100%; left:0; min-width:260px; z-index:9999;"></div>

  </form>



  <ul class="navbar-nav ml-auto">

    <li class="nav-item dropdown">

      <a class="nav-link" data-toggle="dropdown" href="#">

        <div

          style="background: linear-gradient(135deg, #0ea5e9, #2563eb);; color: white; padding: 5px 12px; border-radius: 10px; border: 1px solid rgba(5, 150, 105, 0.1); display: flex; align-items: center; gap: 8px;">



          <i class="fas fa-user-graduate"></i>

          <span class="d-none d-sm-inline" style="font-size: 0.85rem; font-weight: 700;">STUDENT</span>

        </div>

      </a>

      <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">

        <a href="#" class="dropdown-item">

          <i class="far fa-user-circle mr-3"></i> Profile Settings

        </a>

        <div class="dropdown-divider" style="opacity: 0.5;"></div>

        <a href="logoutstd.php" class="dropdown-item text-danger">

          <i class="fas fa-sign-out-alt mr-3"></i> Sign Out

        </a>

      </div>

    </li>

  </ul>

</nav>



<div class="announcement-bar" id="announcementBar">

  <i class="fas fa-bell announcement-icon"></i>

  <div

    style="flex: 1; overflow: hidden; mask-image: linear-gradient(to right, transparent, black 5%, black 95%, transparent);">

    <div class="announcement-track">

      <?php echo $announcementText; ?>

    </div>

  </div>

  <div class="announcement-close" id="announcementClose">

    <i class="fas fa-times" style="font-size: 10px;"></i>

  </div>

</div>



<script>

  (function () {

    var searchRole = '<?php echo isset($searchRole) ? htmlspecialchars($searchRole) : "oldstd"; ?>';

    let t;

    const input = document.getElementById('navSearchStd');

    const box = document.getElementById('navSearchResultsStd');

    if (!input) return;

    input.addEventListener('input', function () {

      clearTimeout(t);

      const q = this.value.trim();

      if (q.length < 2) { box.style.display = 'none'; return; }

      t = setTimeout(() => {

        fetch('includes/search.php?role=' + searchRole + '&q=' + encodeURIComponent(q))

          .then(r => r.json())

          .then(data => {

            if (!data.results.length) {

              box.innerHTML = '<span class="dropdown-item text-muted text-center">No results found</span>';

            } else {

              box.innerHTML = data.results.map(r => {

                const badge = r.type === 'page'

                  ? '<span style="font-size:0.65rem;background:#e0f2fe;color:#0ea5e9;padding:1px 6px;border-radius:4px;margin-left:6px;font-weight:600;">PAGE</span>'

                  : '';

                return '<a href="' + r.url + '" class="dropdown-item">'

                  + '<i class="' + r.icon + ' mr-2" style="color:var(--std-primary)"></i>'

                  + '<span><strong style="display:block;font-size:.85rem">' + r.label + badge + '</strong>'

                  + '<small class="text-muted">' + r.sub + (r.detail && r.detail !== 'Page' ? ' — ' + r.detail : '') + '</small></span>'

                  + '</a>';

              }).join('');

            }

            box.style.display = 'block';

          });

      }, 280);

    });

    document.addEventListener('click', e => {

      if (!input.contains(e.target) && !box.contains(e.target)) box.style.display = 'none';

    });

  })();



  document.addEventListener('DOMContentLoaded', () => {

    const track = document.querySelector('.announcement-track');

    const closeBtn = document.getElementById('announcementClose');

    const bar = document.getElementById('announcementBar');



    // Pause on hover for easier reading

    bar.addEventListener('mouseenter', () => track.style.animationPlayState = 'paused');

    bar.addEventListener('mouseleave', () => track.style.animationPlayState = 'running');



    closeBtn.addEventListener('click', () => {

      bar.style.transition = '0.4s cubic-bezier(1, 0, 0, 1)';

      bar.style.opacity = '0';

      bar.style.transform = 'translateY(-20px)';

      setTimeout(() => bar.remove(), 400);

    });

  });

</script>