
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

function get_rand_gift() {
    // Each segment is 60 degrees for 6 prizes (360 / 6)
    // You can control which segment to land on — e.g., index 2 = 120°
    $segments = [
        30,   // قسيمة 50 درهم
        90,   // قسيمة 125 درهم
        150,  // دخول السحب
        210,  // قسيمة 125 درهم
        270,  // قسيمة 50 درهم
        330   // محاولة أخرى
    ];

    // Choose random segment index (e.g., 0–5)
    $index = rand(0, count($segments) - 1);

    // Return base stop angle (in degrees)
    return $segments[$index];
}


?>

<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
  <meta charset="UTF-8" />
  <title>عجلة الحظ - أمريكانا</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <style>
    body {
      font-family: 'Arial', sans-serif;
      text-align: center;
      background: linear-gradient(to bottom, #ffe000, #2980b9);
      margin: 0;
    }

    .container {
      max-width: 420px;
      margin: auto;
      background: #fff;
      padding: 20px;
      border-radius: 12px;
      box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
    }

    #wheelCanvas {
      margin: 0 auto;
      display: block;
    }

    #pointer {
      position: absolute;
      top: 135px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 10;
      width: 45px;
    }

    #spinBtn {
      margin-top: 20px;
      background-color: #e74c3c;
      color: white;
      font-size: 20px;
      border: none;
      padding: 12px 30px;
      border-radius: 30px;
      cursor: pointer;
    }

    #result {
      margin-top: 20px;
      font-size: 22px;
      color: #2c3e50;
    }

    .wheel-container {
      position: relative;
      width: 360px;
      height: 360px;
      margin: 20px auto;
    }
  </style>
</head>
<body>

<div class="container">
  <img src="assets/logo.png" alt="أمريكانا" width="180">
  <h2 style="color:#e67e22;">العودة للمدارس</h2>
  <p>اشترِ بقيمة ٣٥ درهم من منتجات أمريكانا المجمدة<br>واكسب فرصة لربح جوائز رائعة</p>

  <div class="wheel-container">
    <canvas id="wheelCanvas" width="360" height="360"></canvas>
    <img id="pointer" src="assets/center-pointer3.png" alt="pointer">
  </div>

  <button id="spinBtn" onclick="startSpin()">أدر الآن</button>
  <div id="result"></div>
</div>

<!-- ✅ Include Winwheel.js and TweenMax -->
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.2/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/zarocknz/javascript-winwheel@master/Winwheel.min.js"></script>

<script>
  // ✅ Define the wheel
  const theWheel = new Winwheel({
    canvasId: 'wheelCanvas',
    numSegments: 6,
    'drawMode'       : 'segmentImage',
                'imageDirection' : 'E',
    segments: [
      {'image' : '9.png', 'text' : '120'},
      {'image' : '10.png', 'text' : '120'},
      {'image' : '11.png', 'text' : '120'},
    {'image' : '12.png', 'text' : '120'},
  {'image' : '13.png', 'text' : '120'},
 {'image' : '14.png', 'text' : '120'}
    ],
    animation: {
      type: 'spinToStop',
      duration: 6,
      spins: 7,
      callbackFinished: alertPrize,
      easing: 'Power4.easeOut'
    }
  });

  // ✅ Start spin
  function startSpin() {
    document.getElementById("result").innerText = "";

    // Get stop angle from PHP backend
    let stopAt = <?php echo get_rand_gift(); ?> + Math.floor(Math.random() * 43); // degrees

    theWheel.animation.stopAngle = stopAt;

    // Start the spin
    theWheel.startAnimation();
  }


  // ✅ On complete
  function alertPrize(indicatedSegment) {
    document.getElementById("result").innerText = "🎉 لقد ربحت: " + indicatedSegment.text;
  }
</script>

</body>
</html>