<?php
require_once dirname(__DIR__).'/config.php';
$u=current_user();if(!$u){header('Location: ' . url('?login=1'));exit;}
?><!DOCTYPE html><html lang="ar" dir="rtl"><head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>هدية إلكترونية — سودانا</title>
<style>
:root{--g:#00d97e;--dark:#073328;--bg:#fdf4ff;--card:#fff;--muted:#64748b;--border:#e2e8f0;--safe-bottom:env(safe-area-inset-bottom,0px)}
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:'Cairo',system-ui,sans-serif;background:var(--bg);min-height:100vh;padding-bottom:calc(70px + env(safe-area-inset-bottom,0px));padding-bottom:calc(70px + var(--safe-bottom))}
.hdr{background:var(--dark);height:56px;display:flex;align-items:center;justify-content:space-between;padding:0 16px}
.logo{color:#fff;font-weight:900}.back{color:rgba(255,255,255,.6);font-size:.82rem;text-decoration:none}
.hero{background:linear-gradient(135deg,#5b21b6,#7c3aed);padding:24px 16px;text-align:center}
.hero h1{color:#fff;font-size:1.2rem;font-weight:900}.hero p{color:rgba(255,255,255,.6);font-size:.78rem;margin-top:4px}
.container{max-width:540px;margin:0 auto;padding:16px}
.card{background:var(--card);border:1px solid var(--border);border-radius:20px;padding:24px}
.occasions{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:16px}
.occ-btn{background:#f5f3ff;border:1.5px solid #ddd6fe;border-radius:10px;padding:8px 14px;font-size:.8rem;cursor:pointer;font-family:inherit}
.occ-btn.active{background:#7c3aed;color:#fff;border-color:#7c3aed}
.field{margin-bottom:14px}
.field label{display:block;font-size:.75rem;font-weight:700;color:var(--muted);margin-bottom:5px}
.field input,.field textarea{width:100%;background:#f8fafc;border:1.5px solid var(--border);border-radius:10px;padding:10px 12px;font-family:inherit;font-size:15px}
.field textarea{resize:none;height:72px}
.btn{background:linear-gradient(135deg,#5b21b6,#7c3aed);color:#fff;border:none;border-radius:12px;padding:13px;width:100%;font-family:inherit;font-weight:800;font-size:.9rem;cursor:pointer}
</style></head><body>
<header class="hdr"><div class="logo">🎁 هدية إلكترونية</div><a href="/app/pay.php" class="back">← Pay</a></header>
<div class="hero"><h1>🎁 ابعث هديتك</h1><p>عيديات — مناسبات — نقوط — هدايا بكل مناسبة</p></div>
<div class="container">
  <div class="card">
    <div class="occasions">
      <div class="occ-btn active" onclick="selectOcc(this)">🎉 عامة</div>
      <div class="occ-btn" onclick="selectOcc(this)">🌙 عيد</div>
      <div class="occ-btn" onclick="selectOcc(this)">💒 زواج</div>
      <div class="occ-btn" onclick="selectOcc(this)">🎓 تخرج</div>
      <div class="occ-btn" onclick="selectOcc(this)">👶 مولود</div>
      <div class="occ-btn" onclick="selectOcc(this)">💝 مودة</div>
    </div>
    <div class="field"><label>المستلم (جوال أو رقم حساب)</label>
      <input type="text" id="gift-to" placeholder="0912345678 أو SD2025XXXXXXXX"></div>
    <div class="field"><label>المبلغ (SDG)</label>
      <input type="number" id="gift-amount" placeholder="مثال: 5000" min="100"></div>
    <div class="field"><label>رسالة الهدية 🎁</label>
      <textarea id="gift-msg" placeholder="اكتب رسالتك..."></textarea></div>
    <div class="field"><label>رقم PIN</label>
      <input type="password" id="gift-pin" maxlength="6" placeholder="رقم PIN السري"></div>
    <button class="btn" onclick="sendGift()">🎁 أرسل الهدية</button>
  </div>
</div>
<script>
function selectOcc(el){document.querySelectorAll('.occ-btn').forEach(b=>b.classList.remove('active'));el.classList.add('active');}
async function sendGift(){
  const to=document.getElementById('gift-to').value.trim();
  const amount=parseFloat(document.getElementById('gift-amount').value)||0;
  const msg=document.getElementById('gift-msg').value.trim();
  const pin=document.getElementById('gift-pin').value.trim();
  const occ=document.querySelector('.occ-btn.active')?.textContent||'🎁';
  if(!to||amount<100||!pin){alert('أكمل البيانات المطلوبة');return;}
  const btn=document.querySelector('.btn');btn.disabled=true;btn.textContent='جاري الإرسال...';
  try{
    const r=await fetch('/api/pay/transfer.php',{method:'POST',headers:{'Content-Type':'application/json'},
      body:JSON.stringify({to_phone:to,to_account:to,amount_sdg:amount,pin,narration:occ+' '+msg,idempotency_key:'gift_'+Date.now()})});
    const d=await r.json();
    if(d.ok)alert('🎁 تم إرسال الهدية بنجاح! '+d.txn_ref);
    else alert('❌ '+(d.message||d.error));
  }catch(e){alert('❌ تعذّر الإرسال');}
  btn.disabled=false;btn.textContent='🎁 أرسل الهدية';
}
</script>
<nav style="position:fixed;bottom:0;left:0;right:0;background:#fff;border-top:1px solid #e2e8f0;display:flex;padding:8px 0 calc(8px + env(safe-area-inset-bottom,0px));z-index:100">
  <a href="/app/hub.php" style="flex:1;display:flex;flex-direction:column;align-items:center;gap:2px;text-decoration:none;color:#64748b;font-size:.6rem;font-family:inherit;padding:4px 0"><span style="font-size:1.1rem">&#127968;</span><span>الهب</span></a>
  <a href="/app/pay.php" style="flex:1;display:flex;flex-direction:column;align-items:center;gap:2px;text-decoration:none;color:#00d97e;font-size:.6rem;font-family:inherit;padding:4px 0"><span style="font-size:1.1rem">&#128179;</span><span>Pay</span></a>
  <a href="/app/invest/index.php" style="flex:1;display:flex;flex-direction:column;align-items:center;gap:2px;text-decoration:none;color:#64748b;font-size:.6rem;font-family:inherit;padding:4px 0"><span style="font-size:1.1rem">&#128185;</span><span>استثمار</span></a>
  <a href="/app/community.php" style="flex:1;display:flex;flex-direction:column;align-items:center;gap:2px;text-decoration:none;color:#64748b;font-size:.6rem;font-family:inherit;padding:4px 0"><span style="font-size:1.1rem">&#127968;</span><span>مجتمع</span></a>
  <a href="/app/profile.php" style="flex:1;display:flex;flex-direction:column;align-items:center;gap:2px;text-decoration:none;color:#64748b;font-size:.6rem;font-family:inherit;padding:4px 0"><span style="font-size:1.1rem">&#128100;</span><span>حسابي</span></a>
</nav>
</body></html>
