<?php
require_once __DIR__ . '/auth_helper.php';
if (!check_installed()) { header('Location: install.php'); exit; }
$user = currentUser();
if (!$user) { header('Location: index.php#login'); exit; }
$siteName = 'pk999.com';
$userBal = number_format((float)$user['balance'], 2, '.', ',');
$methods = payment_methods_for_country($user['country_code']);
$depositQuickAmounts = [100,200,500,1000,3000,5000,10000,20000,30000,50000];
$depositMin = 100;
$depositMax = 50000;
?>
<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Deposit - <?= e($siteName) ?></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700;800;900&display=swap" rel="stylesheet">
<style>
:root{--green:#7cff00;--gold:#ffb800;--border:rgba(255,255,255,.10)}*{box-sizing:border-box}body{margin:0;min-height:100vh;background:radial-gradient(circle at 50% -10%,rgba(124,252,0,.16),transparent 40%),#050505;color:#fff;font-family:Poppins,Arial,sans-serif}.top{height:54px;display:flex;align-items:center;gap:12px;padding:0 14px;border-bottom:1px solid var(--border);background:rgba(8,8,8,.94);position:sticky;top:0;z-index:3}.back{width:36px;height:36px;border-radius:50%;display:grid;place-items:center;background:#111;color:#fff;text-decoration:none}.top h1{font-size:17px;margin:0;font-weight:900}.wrap{max-width:760px;margin:0 auto;padding:12px 10px 28px}.panel{border:1px solid rgba(124,252,0,.18);background:linear-gradient(180deg,#111,#090909);border-radius:20px;box-shadow:0 16px 44px rgba(0,0,0,.58);overflow:hidden}.head{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:15px;background:linear-gradient(135deg,#0e190d,#071007 65%,#161206);border-bottom:1px solid rgba(124,252,0,.14)}.head small{display:block;color:#93a18e;font-size:10px;font-weight:900;letter-spacing:.6px;text-transform:uppercase}.head b{display:block;color:#fff;font-size:24px;font-weight:900;margin-top:3px}.head p{margin:4px 0 0;color:#a7b3a1;font-size:11px;line-height:1.35}.badge{width:52px;height:52px;border-radius:18px;display:grid;place-items:center;background:linear-gradient(135deg,#5dda00,var(--green));color:#061006;font-size:22px;box-shadow:0 0 26px rgba(124,252,0,.30)}.body{display:grid;grid-template-columns:162px 1fr;min-height:350px}.side{background:#0a0a0a;border-right:1px solid rgba(255,255,255,.07);padding:12px;display:flex;flex-direction:column;gap:10px}.method{position:relative;display:grid;grid-template-columns:38px 1fr 16px;align-items:center;gap:8px;border:1px solid rgba(255,255,255,.08);background:linear-gradient(180deg,#181818,#101010);border-radius:13px;padding:10px 8px;cursor:pointer;min-height:58px}.method input{display:none}.method.active,.method:has(input:checked){border-color:#ff4c4c;box-shadow:inset 0 0 0 1px rgba(255,76,76,.12),0 0 18px rgba(255,76,76,.10)}.method.active:before,.method:has(input:checked):before{content:"";position:absolute;right:0;top:0;border-top:18px solid #ff4c4c;border-left:18px solid transparent}.method.active:after,.method:has(input:checked):after{content:"✓";position:absolute;right:2px;top:0;color:#fff;font-size:9px;font-weight:900}.logo{width:38px;height:38px;border-radius:10px;display:grid;place-items:center;background:linear-gradient(135deg,#ff2f73,#ff8c00);color:#fff;font-size:14px;font-weight:900}.logo.nagad{background:linear-gradient(135deg,#ffcc00,#ff3c00)}.logo.bank{background:linear-gradient(135deg,#31a8ff,#0066ff)}.mtitle{color:#e8e8e8;font-size:11px;font-weight:900;line-height:1.15}.msub{color:#8a8a8a;font-size:9px;font-weight:800;margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.hot{position:absolute;right:0;top:0;background:#ff8a00;color:#fff;border-radius:0 12px 0 10px;padding:2px 4px;font-size:9px}.main{background:#101010;padding:14px 14px 18px}.info-title{display:flex;align-items:center;gap:8px;color:#f5f5f5;font-size:13px;font-weight:900;border-left:3px solid var(--green);padding-left:8px;margin-bottom:12px}.note{background:rgba(255,115,55,.11);border:1px solid rgba(255,115,55,.23);color:#ffdfca;border-radius:10px;padding:10px 12px;font-size:11px;font-weight:800;line-height:1.45;margin-bottom:13px}.selected{display:inline-flex;align-items:center;gap:7px;border:1px solid rgba(255,76,76,.55);background:rgba(255,76,76,.06);color:#fff;border-radius:8px;padding:8px 10px;font-size:11px;font-weight:900;margin-bottom:13px}.selected i{color:#ff8a00}.warn{display:flex;gap:8px;align-items:center;background:#333;border-radius:7px;padding:8px 10px;margin-bottom:14px;color:#fff;font-size:10px;line-height:1.35;max-width:560px;box-shadow:0 4px 10px rgba(0,0,0,.35)}.dot{width:19px;height:19px;border-radius:50%;display:grid;place-items:center;background:#ff3333;color:#fff;font-weight:900;flex:0 0 auto}.amount-row{display:flex;align-items:flex-start;gap:9px;flex-wrap:wrap}.label{color:#d7d7d7;font-size:12px;margin-top:9px;min-width:70px}.amounts{display:flex;flex-wrap:wrap;gap:9px;max-width:550px}.amount-btn{min-width:49px;height:29px;padding:0 10px;border-radius:6px;border:1px solid rgba(255,76,76,.35);background:#161616;color:#d9d9d9;font-size:11px;font-weight:800;cursor:pointer}.amount-btn.active{background:linear-gradient(135deg,#ff3030,#ff7a00);color:#fff;border-color:#ff6b00;box-shadow:0 0 15px rgba(255,78,0,.25)}.custom{margin:10px 0 0 79px;width:168px;height:35px;border:1px solid rgba(255,255,255,.12);background:#0b0b0b;color:#fff;border-radius:8px;padding:0 12px;font-size:12px;outline:0}.custom:focus{border-color:var(--green);box-shadow:0 0 0 3px rgba(124,252,0,.08)}.rules{margin:9px 0 0 79px;color:#ff4040;font-size:11px;font-weight:900;line-height:1.7}.submit{margin:70px 0 0 12px;border:0;border-radius:999px;background:linear-gradient(135deg,#ff2f48,#ff5633);color:#fff;font-size:12px;font-weight:900;padding:11px 20px;box-shadow:0 10px 24px rgba(255,47,72,.25);cursor:pointer}.nomethod{padding:15px;border:1px solid rgba(255,80,80,.25);background:rgba(255,80,80,.08);color:#ffb7b7;border-radius:14px;font-size:12px;font-weight:800}@media(max-width:640px){.body{grid-template-columns:1fr}.side{border-right:0;border-bottom:1px solid rgba(255,255,255,.07);display:grid;grid-template-columns:repeat(2,1fr)}.main{padding:13px}.warn{font-size:9px}.amount-row{display:block}.label{margin:0 0 8px}.amounts{gap:7px}.amount-btn{min-width:54px}.custom,.rules{margin-left:0}.submit{margin:24px 0 0;width:100%;border-radius:14px;height:48px}.head b{font-size:21px}}
</style>
</head>
<body>
<div class="top"><a href="index.php" class="back"><i class="fas fa-chevron-left"></i></a><h1>Deposit</h1></div>
<div class="wrap">
  <div class="panel">
    <div class="head"><div><small>Available Balance</small><b>৳ <?= e($userBal) ?></b><p>Amount select করে payment page-এ যান।</p></div><div class="badge"><i class="fas fa-wallet"></i></div></div>
    <?php if($methods): ?>
    <form class="body" action="payment.php" method="get" id="depositSelectForm">
      <div class="side">
        <?php foreach($methods as $i=>$m): $prov=strtolower((string)($m['provider'].' '.$m['label'].' '.$m['method_key'])); $logoClass=(strpos($prov,'nagad')!==false?'nagad':(strpos($prov,'bank')!==false?'bank':'')); ?>
        <label class="method <?= $i===0?'active':'' ?>" onclick="selectMethod(this)">
          <input type="radio" name="method_id" value="<?= (int)$m['id'] ?>" data-label="<?= e($m['label']) ?>" <?= $i===0?'checked':'' ?>>
          <div class="logo <?= e($logoClass) ?>"><?= e(strtoupper(substr(trim((string)$m['label']),0,1))) ?></div>
          <div><div class="mtitle"><?= e($m['label']) ?></div><div class="msub"><?= e($m['provider'] ?: 'Payment') ?></div></div><span class="hot"><i class="fas fa-fire"></i></span>
        </label>
        <?php endforeach; ?>
      </div>
      <div class="main">
        <div class="info-title"><i class="fas fa-info-circle"></i> জমার তথ্য</div>
        <div class="note">!!! NOTE : অনুগ্রহ করে payment page-এ যাওয়ার আগে amount select করুন। একই amount cashout করে TrxID submit করুন। Admin approve করলে balance add হবে। ⚠️⚠️⚠️</div>
        <div class="selected"><i class="fas fa-thumbs-up"></i> <span id="selectedMethodName"><?= e($methods[0]['label'] ?? 'Payment') ?></span> <span>/ LKP</span></div>
        <div class="warn"><span class="dot">!</span><span>সতর্ক থাকুন। সঠিক wallet number ও amount ছাড়া payment করলে credit fail হতে পারে।</span></div>
        <div class="amount-row"><div class="label">জমার পরিমান:</div><div class="amounts"><?php foreach($depositQuickAmounts as $qa): ?><button class="amount-btn" type="button" onclick="pickAmount(this,'<?= (int)$qa ?>')"><?= number_format((int)$qa) ?></button><?php endforeach; ?></div></div>
        <input class="custom" type="number" name="amount" min="<?= (int)$depositMin ?>" max="<?= (int)$depositMax ?>" step="1" placeholder="জমার পরিমান" required oninput="clearButtons()">
        <div class="rules">জমা সীমা: ৳ <?= number_format((int)$depositMin) ?> - ৳ <?= number_format((int)$depositMax) ?><br>জমারসময়: 24/24</div>
        <button class="submit" type="submit"><i class="fas fa-paper-plane"></i> জমার জন্য আবেদন করুন</button>
      </div>
    </form>
    <?php else: ?><div class="main"><div class="nomethod">No payment method is active right now. Please add method from admin panel.</div></div><?php endif; ?>
  </div>
</div>
<script>
function selectMethod(tile){document.querySelectorAll('.method').forEach(x=>x.classList.remove('active')); tile.classList.add('active'); const inp=tile.querySelector('input[name=method_id]'); if(inp){inp.checked=true; document.getElementById('selectedMethodName').textContent=inp.dataset.label||'Payment';}}
function pickAmount(btn,val){document.querySelector('[name=amount]').value=val; document.querySelectorAll('.amount-btn').forEach(x=>x.classList.remove('active')); btn.classList.add('active');}
function clearButtons(){document.querySelectorAll('.amount-btn').forEach(x=>x.classList.remove('active'));}
document.getElementById('depositSelectForm')?.addEventListener('submit',function(e){const amount=Number(this.amount.value||0); if(amount < <?= (int)$depositMin ?> || amount > <?= (int)$depositMax ?>){e.preventDefault(); alert('জমা সীমা: ৳<?= (int)$depositMin ?> - ৳<?= number_format((int)$depositMax) ?>');}});
</script>
</body>
</html>
