<?php
/* ============================================================================
   splash.php — Dabil Loading / Splash Experience
   ----------------------------------------------------------------------------
   First impression of Dabil: a calm, premium "aperture of light" that presents
   the wordmark, then dissolves into the destination page.

   Server's only job here is to decide where the visitor goes next; the splash
   itself is purely presentational (markup + assets/css/splash.css + assets/js/
   splash.js). Destination is handed to the client via a data- attribute so the
   PHP and the front-end logic stay cleanly separated.

   Routing (unchanged from the original):
     • Active customer session   -> dashboard.php  (already signed in)
     • "dabil_returning" cookie   -> signin.php     (knows us, session expired)
     • Otherwise                  -> welcome.php    (first-time visitor)
   ============================================================================ */

session_start();

if (isset($_SESSION['user_id']) && (($_SESSION['role'] ?? '') === 'customer')) {
    $redirectTarget = 'dashboard.php';
} elseif (!empty($_COOKIE['dabil_returning'])) {
    $redirectTarget = 'signin.php';
} else {
    $redirectTarget = 'welcome.php';
}

/* Cache-bust the assets so design tweaks always reach the browser. */
$ver = '1.0';
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  <meta name="theme-color" content="#FFFFFF">
  <title>Dabil</title>

  <!-- Splash styles -->
  <link rel="stylesheet" href="assets/css/splash.css?v=<?php echo $ver; ?>">

  <!-- Preload the hero so the logo never pops in late -->
  <link rel="preload" as="image" href="assets/img/dlogo.png">

  <style>
    /* Keep the page itself white from the very first paint (avoids any flash
       before splash.css applies). Scoped, minimal, inlined on purpose. */
    html, body { height: 100%; margin: 0; background: #FFFFFF; overflow: hidden; }
  </style>
</head>
<body>

  <!--
    The splash stage. data-target   = where to navigate after the dissolve.
                       data-min-hold = minimum ms on screen (lets the motion play).
  -->
  <div class="dabil-splash"
       role="status"
       aria-label="Dabil is loading"
       data-target="<?php echo htmlspecialchars($redirectTarget, ENT_QUOTES); ?>"
       data-min-hold="2600">

    <!-- Flowing multi-hue aurora light field -->
    <div class="dabil-aurora" aria-hidden="true">
      <span class="a1"></span><span class="a2"></span>
      <span class="a3"></span><span class="a4"></span>
    </div>

    <!-- Living node network (the "Dabil connects" constellation) -->
    <canvas class="dabil-network" aria-hidden="true"></canvas>

    <!-- Concentric group: pulses, halo, core, logo — all share one center -->
    <div class="dabil-center">
      <!-- Confirmation heartbeat: lead pulse reveals the logo, then a calm loop -->
      <span class="dabil-pulse lead" aria-hidden="true"></span>
      <span class="dabil-pulse p1"  aria-hidden="true"></span>
      <span class="dabil-pulse p2"  aria-hidden="true"></span>
      <span class="dabil-pulse p3"  aria-hidden="true"></span>

      <!-- Persistent halo rings with a slowly rotating light arc -->
      <span class="dabil-halo h2" aria-hidden="true"></span>
      <span class="dabil-halo h1" aria-hidden="true"></span>

      <!-- Luminous backing keeps the mark crisp above the network -->
      <span class="dabil-backing" aria-hidden="true"></span>

      <!-- Ignition spark -->
      <span class="dabil-core" aria-hidden="true"></span>

      <!-- The hero: the Dabil logo, exactly as supplied -->
      <img class="dabil-logo"
           src="assets/img/dlogo.png"
           alt="Dabil"
           decoding="async"
           fetchpriority="high">

      <!-- One light glint, masked to the logo's silhouette -->
      <span class="dabil-sheen"
            aria-hidden="true"
            style="--logo-src: url('assets/img/dlogo.png?v=<?php echo $ver; ?>');"></span>
    </div>

    <!-- A few rising motes for atmosphere; injected by splash.js -->
    <div class="dabil-motes" aria-hidden="true"></div>
  </div>

  <noscript>
    <!-- No JS? Send the visitor straight on; no one waits on a blank screen. -->
    <meta http-equiv="refresh"
          content="2; url=<?php echo htmlspecialchars($redirectTarget, ENT_QUOTES); ?>">
  </noscript>

  <script src="assets/js/splash.js?v=<?php echo $ver; ?>"></script>
</body>
</html>
