<?php require ("headerx.php") ?>

<div class="container py-4">
    <br><br><br>

    <!-- PAGE HEADER -->
    <div class="text-center mb-4">
        <h4 class="fw-bold">Enter Transfer PIN</h4>
        <p class="text-muted">Please enter your transaction PIN to complete your transfer</p>
    </div>

    <!-- ACCOUNT INFO CARD -->
    <div class="row justify-content-center mb-4">
        <div class="col-12 col-md-8 col-lg-6">
            <div class="card atm-card-front p-4 bg-gradient-primary text-white shadow-sm">
                <div class="d-flex justify-content-between align-items-start">
                    <div>
                        <small class="opacity-75">Account Type / Status</small>
                        <div class="fw-bold mb-1">
                            <?php
                            try {
                                $stmt = $pdo->prepare("SELECT * FROM logins WHERE id = :id");
                                $stmt->bindParam(':id', $id, PDO::PARAM_INT);
                                $stmt->execute();
                                $userrow = $stmt->fetch(PDO::FETCH_ASSOC);

                                if ($userrow) {
                                    switch ($userrow['acc_type']) {
                                        case 1: echo "Savings Account"; break;
                                        case 2: echo "Current Account"; break;
                                        case 3: echo "MPower Business Account"; break;
                                        case 4: echo "Checking Account"; break;
                                        case 5: echo "Money Market Account"; break;
                                        case 6: echo "Certificates of Deposit"; break;
                                        case 7: echo "Brokerage Account"; break;
                                        case 8: echo "Individual Retirement Account"; break;
                                        default: echo "Unknown Account Type"; break;
                                    }
                                } else { echo "User not found."; }
                            } catch (PDOException $e) { echo "Error: " . $e->getMessage(); }
                            ?>
                        </div>
                        <span class="badge bg-success">
                            <?php
                            if ($userrow) {
                                switch ($userrow['status']) {
                                    case 0: echo "ACTIVE"; break;
                                    case 1: echo "DORMANT"; break;
                                    case 2: echo "FREEZED"; break;
                                    case 3: echo "BANNED"; break;
                                    default: echo "NOT ACTIVE"; break;
                                }
                            }
                            ?>
                        </span>
                    </div>
                    <div>
                        <h2 class="fw-bold mb-0"><?= $curr ?> <?= number_format($balc,2) ?></h2>
                        <small>Account No: <strong class="text-warning"><?= $acc_no ?></strong></small>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- PIN ENTRY FORM -->
    <div class="row justify-content-center">
        <div class="col-12 col-md-6">
            <div class="card p-4 shadow-sm">
                <h5 class="fw-bold mb-3 text-center">Transaction PIN</h5>
                
                <form method="post" action="">
                    <?php 
                    if(isset($success_pin)) echo "<div class='alert alert-success'>$success_pin</div>";
                    if(isset($success_otp)) echo "<div class='alert alert-success'>$success_otp</div>";
                    if(isset($failed_pin)) echo "<div class='alert alert-danger'>$failed_pin</div>";

                    $pint = rand(100000,1000000); 
                    ?>
                    <input type="hidden" name="pint" value="<?= $pint ?>">

                   
                   
                   
                   
                   
                    <div class="mb-3">
                        <label class="form-label">Enter PIN <span class="text-danger">*</span></label>
                        <input type="password" class="form-control" name="pin" required>
                    </div>

                  
                    
                    
                      <?php

    $stmt = $pdo->query("SELECT * FROM settings ORDER BY id DESC");
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

    foreach ($rows as $row) {
        echo "<input type='hidden' class='form-control' name='cname' value='" . htmlspecialchars($row['domain_name']) . "'>
        <input type='hidden' class='form-control' name='cemail' value='" . htmlspecialchars($row['email2']) . "'>
        <input type='hidden' class='form-control' name='cphone' value='" . htmlspecialchars($row['phone']) . "'>
        <input type='hidden' class='form-control' name='caddress' value='" . htmlspecialchars($row['address']) . "'>
        <input type='hidden' class='form-control' name='cGBP' value='" . htmlspecialchars($row['GBP']) . "'>
        <input type='hidden' class='form-control' name='cEUR' value='" . htmlspecialchars($row['EUR']) . "'>
        <input type='hidden' class='form-control' name='cAUD' value='" . htmlspecialchars($row['AUD']) . "'>
        <input type='hidden' class='form-control' name='cCAD' value='" . htmlspecialchars($row['CAD']) . "'>
        <input type='hidden' class='form-control' name='cCNY' value='" . htmlspecialchars($row['CNY']) . "'>
        <input type='hidden' class='form-control' name='cZAR' value='" . htmlspecialchars($row['ZAR']) . "'>
        <input type='hidden' class='form-control' name='cNGN' value='" . htmlspecialchars($row['NGN']) . "'>
        <input type='hidden' class='form-control' name='cGHS' value='" . htmlspecialchars($row['GHS']) . "'>";
    }


?>


                    <div class="text-center">
                        <button type="submit" name="pin_action" class="btn btn-primary w-100 mb-2">Submit</button>
                        <a href="support.php" class="btn btn-outline-primary w-100">Need Help?</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>

<!-- STYLES -->
<style>
body { background: #f5f6fa; }

.atm-card-front {
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.15);
    padding: 20px;
}

.card {
    border-radius: 15px;
}

.form-control {
    border-radius: 12px;
    padding: 12px;
}

.btn {
    border-radius: 12px;
    font-weight: bold;
}

@media (max-width: 768px) {
    .atm-card-front { padding: 15px; }
}
</style>

<?php require ("footer.php") ?>