<?php
require_once("auth.php");

$message = '';
$message_type = '';

/* ══════════════════════════════════════════════════════════
   REMOVED — Agent আর নিজে Deposit Request Accept/Reject করতে
   পারবে না। এই কাজ এখন শুধুমাত্র Admin Panel থেকে করতে হবে।
   Agent এই পেজে শুধু নিজের downline-এর pending request দেখতে
   পারবে, কোনো action নিতে পারবে না।
   ══════════════════════════════════════════════════════════ */

$requests = [];
if ($agent_owncode !== '') {
    $q = mysqli_query($conn,
        "SELECT t.shonu, t.balakedara, t.motta, t.mula, t.ullekha, t.duravani, t.dinankavannuracisi, ss.mobile
         FROM thevani t
         JOIN shonu_subjects ss ON ss.id = t.balakedara
         WHERE ss.code = '$agent_owncode' AND t.sthiti = '0'
         ORDER BY t.shonu DESC"
    );
    while ($r = mysqli_fetch_assoc($q)) { $requests[] = $r; }
}

include("header.php");
?>

<div class="al-wrap">
  <div class="al-page-title">Deposit Requests</div>
  <div class="al-page-sub">তোমার downline User-দের pending deposit — Accept করলে balance তোমার থেকে কাটবে</div>

  <?php if ($message): ?>
  <div class="al-alert al-alert-<?php echo $message_type; ?>"><?php echo htmlspecialchars($message); ?></div>
  <?php endif; ?>

  <?php if (empty($requests)): ?>
    <div class="al-table-wrap"><div class="al-empty"><div class="icon">📭</div><div class="msg">এই মুহূর্তে কোনো Pending Deposit Request নেই।</div></div></div>
  <?php else: ?>
    <?php foreach ($requests as $r): ?>
    <div class="al-card credit">
      <div style="display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:10px;">
        <div class="amt mono">৳<?php echo number_format($r['motta'],2); ?></div>
        <span class="al-stamp warn"><?php echo htmlspecialchars($r['mula'] ?: 'deposit'); ?></span>
      </div>
      <div class="row">User: <b><?php echo htmlspecialchars($r['mobile']); ?></b> · ID <?php echo $r['balakedara']; ?></div>
      <div class="row">Transaction ID: <b class="mono"><?php echo htmlspecialchars($r['ullekha']); ?></b></div>
      <?php if (!empty($r['duravani'])): ?>
      <div class="row">পাঠানো নাম্বার: <b class="mono"><?php echo htmlspecialchars($r['duravani']); ?></b></div>
      <?php endif; ?>
      <div class="row" style="color:var(--text-faint);font-size:11.5px;"><?php echo htmlspecialchars($r['dinankavannuracisi']); ?></div>

      <div class="al-alert" style="margin-top:14px;background:rgba(245,197,66,.1);color:var(--gold);border-color:rgba(245,197,66,.3);">
        ⏳ Pending — শুধু Admin এই Request Accept/Reject করতে পারবে।
      </div>
    </div>
    <?php endforeach; ?>
  <?php endif; ?>
</div>
</body>
</html>
