<?php
include 'header.php';

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Store deposit details in session
    $_SESSION['deposit_details'] = [
        'amount' => floatval($_POST['amount']),
        'coin' => htmlspecialchars($_POST['coin']),
        'receiving_amount' => floatval($_POST['amount']) * (1 - ($deposits_charge / 100)),
        'method' => 'Crypto Payment Method'
    ];
    
    // Redirect to manual payment page
echo "<script>window.location.href = 'manual.php';</script>";

    exit;
}

?>

<!-- Rest of your existing HTML/PHP code -->

<div class="pt-28 md:pt-0 mt-0 md:mt-36 w-full md:w-4/5" id="general-content">
    <div class="w-full md:w-10/12 md:ml-64 2xl:ml-1/5" id="general-content-section">
        <div class="w-full py-5">
            <div class="w-full flex justify-center">
                <div class="w-11/12 rounded-md bg-[#0e1726] p-2 md:p-4">
                    <div class="flex justify-between items-center">
                        <div>
                            <h2 class="bg-transparent text-[#ebedf2] font-medium capitalize text-lg md:text-xl">
                                Cryptocurrency Deposit
                            </h2>
                        </div>
                        <div>
                           <a href="javascript:history.back()"
   class="flex justify-start items-center text-xs text-gray-400 hover:text-white">
    <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24"
         stroke="currentColor" stroke-width="2">
        <path stroke-linecap="round" stroke-linejoin="round" d="M11 17l-5-5m0 0l5-5m-5 5h12" />
    </svg>
    <span>Back</span>
</a>

                        </div>
                    </div>
                </div>
            </div>
        </div>

        <form action="" method="POST" id="depositForm">
           
            <div class="w-full py-5">
                <div class="w-full flex justify-center">
                    <div class="w-11/12 rounded-md bg-[#0e1726] p-2 md:p-4">
                        <div class="p-2 md:p-4">
                            <div class="flex justify-center w-full">
                                <div class="w-3/4 md:w-1/2">
                                    <!-- Payment Method Carousel -->
                                    <div class="owl-carousel owl-theme w-full">
                                        <div class="w-full flex justify-center my-3">
                                            <div class="w-60 item bg-[#1b2e4b] text-[#d1d5db] border border-gray-700 rounded-md hover:border-blue-500 transition duration-200">
                                                <label for="32" class="cursor-pointer">
                                                    <div class="flex justify-center p-4">
                                                        <div class="w-40 h-40">
                                                            <img class="min-h-full min-w-full rounded-full"
                                                                src="image/deposit.png"
                                                                alt="Crypto Payment">
                                                        </div>
                                                    </div>
                                                    <div class="text-xs md:text-sm">
                                                        <h3 class="font-semibold text-lg md:text-xl text-center py-2">
                                                            Crypto Payment Method</h3>
                                                        <div class="flex justify-center">
                                                            <tr>
                                                                <td>Min:</td>
                                                                <td>USD<?php echo number_format($min_deposits, 2) ?></td>
                                                            </tr>
                                                        </div>
                                                        <div class="flex justify-center">
                                                            <tr>
                                                                <td>Max:</td>
                                                                <td>USD<?php echo number_format($max_deposits, 2) ?></td>
                                                            </tr>
                                                        </div>
                                                        <div class="flex justify-center">
                                                            <tr>
                                                                <td>Charge:</td>
                                                                <td><?php echo $deposits_charge ?>%</td>
                                                            </tr>
                                                        </div>
                                                    </div>
                                                </label>
                                                <div class="flex justify-center py-3">
                                                    <input type="radio" id="32" checked name="method_id" value="32" required
                                                        class="funny-radio">
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Amount Input -->
                                    <div class="relative w-full mt-4">
                                        <div class="relative">
                                            <svg xmlns="http://www.w3.org/2000/svg"
                                                class="cred-hyip-theme1-input-icon h-8 w-8" fill="none" viewBox="0 0 24 24"
                                                stroke="currentColor" stroke-width="2">
                                                <path stroke-linecap="round" stroke-linejoin="round"
                                                    d="M17 9V7a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2m2 4h10a2 2 0 002-2v-6a2 2 0 00-2-2H9a2 2 0 00-2 2v6a2 2 0 002 2zm7-5a2 2 0 11-4 0 2 2 0 014 0z" />
                                            </svg>
                                            <input type="number" step="0.01" min="<?php echo $min_deposits ?>" max="<?php echo $max_deposits ?>" 
                                                name="amount" id="amount" required
                                                class="cred-hyip-theme1-text-input w-full" 
                                                placeholder="Enter amount to deposit (USD)">
                                        </div>
                                        <div class="flex justify-between mt-1 text-xs text-gray-400">
                                            <span>Min: $<?php echo number_format($min_deposits, 2) ?></span>
                                            <span>Max: $<?php echo number_format($max_deposits, 2) ?></span>
                                        </div>
                                    </div>

                                    <!-- Cryptocurrency Selection -->
                                    <div class="relative w-full mt-4">
                                        <select name="coin" id="coin" required
                                            class="cred-hyip-theme1-text-input appearance-none w-full">
                                            <option value="">Select Cryptocurrency</option>
                                            <option value="BTC">Bitcoin (BTC)</option>
                                            <option value="ETH">Ethereum (ETH)</option>
                                            <option value="USDT-ERC20">Tether (USDT-ERC20)</option>
                                            <option value="USDT-TRC20">Tether (USDT-TRC20)</option>
                                            <option value="BNB">Binance Coin (BNB)</option>
                                            <option value="XRP">Ripple (XRP)</option>
                                            <option value="SOL">Solana (SOL)</option>
                                            <option value="LTC">litecoin (LTC)</option>
                                           
                                        </select>
                                        <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-400">
                                            <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
                                                <path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/>
                                            </svg>
                                        </div>
                                    </div>

                                    <!-- Estimated Amount Display -->
                                    <div class="bg-[#1b2e4b] rounded-md p-3 mt-4 border border-gray-700">
                                        <div class="flex justify-between items-center">
                                            <span class="text-gray-400">You will receive:</span>
                                            <span class="font-medium" id="receivingAmount">
                                                $0.00 (after <?php echo $deposits_charge ?>% fee)
                                            </span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <hr class="w-full border-b border-dotted border-gray-600 border mt-2">

                        <div class="w-full my-5 px-5 flex justify-center">
                            <button type="submit"
                                class="w-2/3 text-xs md:text-sm text-[#d1d5db] text-center px-5 py-3 bg-[#1b2e4b] hover:bg-gray-700 rounded-md transition duration-200">
                                Generate Deposit Address
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </form>

        <script>
            $(document).ready(function() {
                // Initialize carousel
                $('.owl-carousel').owlCarousel({
                    loop: true,
                    dots: false,
                    items: 1,
                    margin: 20,
                    responsive: {
                        768: {
                            nav: true
                        }
                    }
                });

                // Calculate receiving amount after fee
                $('#amount').on('input', function() {
                    const amount = parseFloat($(this).val()) || 0;
                    const feePercentage = <?php echo $deposits_charge ?>;
                    const feeAmount = amount * (feePercentage / 100);
                    const receivingAmount = amount - feeAmount;
                    
                    $('#receivingAmount').text('$' + receivingAmount.toFixed(2) + 
                        ' (after <?php echo $deposits_charge ?>% fee)');
                });

                // Form validation
                $('#depositForm').submit(function(e) {
                    const amount = parseFloat($('#amount').val());
                    const coin = $('#coin').val();
                    
                    if (amount < <?php echo $min_deposits ?>) {
                        e.preventDefault();
                        alert('Minimum deposit amount is $<?php echo number_format($min_deposits, 2) ?>');
                        return false;
                    }
                    
                    if (amount > <?php echo $max_deposits ?>) {
                        e.preventDefault();
                        alert('Maximum deposit amount is $<?php echo number_format($max_deposits, 2) ?>');
                        return false;
                    }
                    
                    if (!coin) {
                        e.preventDefault();
                        alert('Please select a cryptocurrency');
                        return false;
                    }
                });
            });
        </script>
    </div>


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