<?php
require_once 'common/config.php';
include 'common/header.php';

// ইউজার লগইন না থাকলে লগইন পেজে পাঠিয়ে দিবে
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$error = ""; $success = "";

if (isset($_POST['deposit'])) {
    $user_id = $_SESSION['user_id'];
    $amount = mysqli_real_escape_string($conn, $_POST['amount']);
    $method = mysqli_real_escape_string($conn, $_POST['method']);
    $txid = mysqli_real_escape_string($conn, $_POST['txid']);

    if ($amount < 10) {
        $error = "DEPOSIT_ERROR: Minimum amount is ৳10";
    } else {
        $stmt = $conn->prepare("INSERT INTO deposits (user_id, amount, method, transaction_id, status) VALUES (?, ?, ?, ?, 'pending')");
        $stmt->bind_param("idss", $user_id, $amount, $method, $txid);
        
        if ($stmt->execute()) {
            $success = "REQUEST_SENT: Your request is pending for verification.";
        } else {
            $error = "SYSTEM_ERROR: Data transmission failed!";
        }
    }
}
?>

<div class="flex items-center justify-center min-h-[calc(100vh-80px)] px-4 py-10">
    <div class="cyber-card w-full max-w-5xl overflow-hidden border-t-4 border-cyan-500/50 shadow-2xl">
        
        <div class="flex flex-col lg:flex-row">
            <!-- বাম অংশ: পেমেন্ট ইনস্ট্রাকশন -->
            <div class="lg:w-5/12 bg-slate-900/60 p-8 md:p-12 border-b lg:border-b-0 lg:border-r border-white/5 relative overflow-hidden">
                <div class="absolute -top-10 -left-10 w-40 h-40 bg-cyan-500/5 rounded-full blur-3xl"></div>
                
                <h2 class="text-2xl md:text-3xl font-bold logo-font tracking-tighter text-white uppercase mb-8">
                    PAYMENT <span class="text-cyan-400 glow-text">INFO</span>
                </h2>

                <div class="space-y-6 relative">
                    <!-- বিকাশ -->
                    <div class="bg-black/40 border border-pink-500/20 p-4 rounded-2xl flex items-center space-x-4">
                        <div class="w-12 h-12 bg-pink-500/10 rounded-xl flex items-center justify-center text-pink-500 border border-pink-500/30">
                            <i class="fa-solid fa-mobile-screen-button text-xl"></i>
                        </div>
                        <div>
                            <p class="text-[10px] font-black text-gray-500 uppercase tracking-widest">bKash (Personal)</p>
                            <p class="text-lg font-bold text-white tracking-widest">01794593698</p>
                        </div>
                    </div>

                    <!-- নগদ -->
                    <div class="bg-black/40 border border-orange-500/20 p-4 rounded-2xl flex items-center space-x-4">
                        <div class="w-12 h-12 bg-orange-500/10 rounded-xl flex items-center justify-center text-orange-500 border border-orange-500/30">
                            <i class="fa-solid fa-wallet text-xl"></i>
                        </div>
                        <div>
                            <p class="text-[10px] font-black text-gray-500 uppercase tracking-widest">Nagad (Personal)</p>
                            <p class="text-lg font-bold text-white tracking-widest">OFF</p>
                        </div>
                    </div>

                    <div class="mt-8 p-4 bg-cyan-500/5 border border-cyan-500/20 rounded-xl">
                        <p class="text-[11px] text-cyan-400 font-bold uppercase tracking-wider leading-relaxed">
                            <i class="fa-solid fa-circle-info mr-2"></i> 
                            প্রথমে উপরের নাম্বারে 'Send Money' করুন, তারপর নিচের ফর্মটি পূরণ করুন। ৫-৩০ মিনিটের মধ্যে টাকা এড হয়ে যাবে।
                        </p>
                    </div>
                </div>
            </div>

            <!-- ডান অংশ: ডিপোজিট ফর্ম -->
            <div class="lg:w-7/12 p-8 md:p-12 bg-slate-950/20">
                <h3 class="text-xl md:text-2xl font-bold logo-font text-white uppercase mb-8 tracking-widest">Submit <span class="text-cyan-400">Request</span></h3>

                <?php if($error): ?>
                    <div class="bg-red-500/10 border border-red-500/30 text-red-500 p-4 rounded-xl mb-6 text-xs font-bold uppercase tracking-widest">
                        <i class="fa-solid fa-triangle-exclamation mr-2"></i> <?php echo $error; ?>
                    </div>
                <?php endif; ?>

                <?php if($success): ?>
                    <div class="bg-green-500/10 border border-green-500/30 text-green-500 p-4 rounded-xl mb-6 text-xs font-bold uppercase tracking-widest animate-pulse">
                        <i class="fa-solid fa-check-circle mr-2"></i> <?php echo $success; ?>
                    </div>
                <?php endif; ?>

                <form action="" method="POST" class="space-y-6">
                    <!-- মেথড সিলেক্ট -->
                    <div class="space-y-2">
                        <label class="block text-[10px] font-black text-gray-500 uppercase tracking-[3px] ml-1">Select Gateway</label>
                        <select name="method" required class="w-full bg-slate-900 border border-white/10 rounded-2xl py-4 px-6 text-white focus:border-cyan-500 outline-none transition-all appearance-none cursor-pointer">
                            <option value="bKash">bKash</option>
                            <option value="Nagad">Nagad</option>
                            <option value="Rocket">Rocket</option>
                        </select>
                    </div>

                    <!-- অ্যামাউন্ট -->
                    <div class="space-y-2">
                        <label class="block text-[10px] font-black text-gray-500 uppercase tracking-[3px] ml-1">Amount (BDT)</label>
                        <div class="relative group">
                            <i class="fa-solid fa-bangladeshi-taka-sign absolute left-5 top-1/2 -translate-y-1/2 text-cyan-500/30 text-xl"></i>
                            <input type="number" name="amount" required placeholder="0.00" 
                                   class="w-full bg-slate-900 border border-white/10 rounded-2xl py-4 pl-14 pr-6 text-white focus:border-cyan-500 outline-none text-xl font-bold">
                        </div>
                    </div>

                    <!-- ট্রানজেকশন আইডি -->
                    <div class="space-y-2">
                        <label class="block text-[10px] font-black text-gray-500 uppercase tracking-[3px] ml-1">Transaction ID (TxID)</label>
                        <div class="relative group">
                            <i class="fa-solid fa-receipt absolute left-5 top-1/2 -translate-y-1/2 text-cyan-500/30 text-xl"></i>
                            <input type="text" name="txid" required placeholder="TRX123456789" 
                                   class="w-full bg-slate-900 border border-white/10 rounded-2xl py-4 pl-14 pr-6 text-white focus:border-cyan-500 outline-none text-lg font-mono tracking-widest">
                        </div>
                    </div>

                    <button type="submit" name="deposit" 
                            class="w-full bg-gradient-to-r from-cyan-600 to-blue-700 text-white font-black py-5 rounded-2xl shadow-lg hover:shadow-cyan-500/20 active:scale-95 transition-all uppercase tracking-[5px] text-sm mt-4">
                        PROCEED DEPOSIT
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>

<style>
    .cyber-card {
        background: rgba(1, 10, 32, 0.9);
        backdrop-filter: blur(30px);
        border: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 3rem;
    }
</style>

<?php include 'common/footer.php'; ?>