<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start();
require_once("../config.php");

// Check if user is logged in
if (!isset($_SESSION['SESS_LOGGEDIN']) || $_SESSION['SESS_LOGGEDIN'] !== true) {
    header("Location: " . $config_basedir . "logout.php");
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title><?php echo $title ?></title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

<style>

/* GLOBAL RESET */
body {
    background: linear-gradient(135deg, #0a2a43, #014E72);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #333;
}

/* CENTER CARD */
.success-card {
    max-width: 500px;
    margin: 80px auto;
    background: #ffffff;
    border-radius: 12px;
    padding: 30px 25px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    animation: fadeInUp 0.8s ease;
}

/* SUCCESS ICON */
.success-icon {
    font-size: 60px;
    color: #28a745;
    margin-bottom: 15px;
    animation: pop 0.5s ease;
}

/* TEXT */
.success-text {
    font-size: 16px;
    margin-bottom: 20px;
    line-height: 1.6;
}

/* ACCOUNT NUMBER */
.acc-number {
    color: #014E72;
    font-weight: bold;
}

/* LOADER */
.loader {
    margin: 20px auto;
    border: 6px solid #eee;
    border-top: 6px solid #014E72;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

/* REDIRECT TEXT */
.redirect-text {
    font-size: 13px;
    color: #777;
}

/* ANIMATIONS */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(40px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pop {
    0% { transform: scale(0.5); }
    100% { transform: scale(1); }
}

/* RESPONSIVE */
@media (max-width: 600px) {
    .success-card {
        margin: 40px 15px;
        padding: 25px 15px;
    }

    .success-text {
        font-size: 14px;
    }
}

</style>
</head>

<?php
$seller = $_SESSION['SESS_USERID'];

$stmt = $pdo->prepare("SELECT * FROM logins WHERE id = ?");
$stmt->execute([$seller]);
$serow = $stmt->fetch(PDO::FETCH_ASSOC);

$forename = $serow['firstname'];
$surname  = $serow['lastname'];
$add1     = $serow['country'];
$add3     = $serow['state'];
$city     = $serow['city'];
// $currency = $serow['currency'];
// $curr     = $serow['currency'];
$phone    = $serow['phone'];
$email    = $serow['email'];
$acc_no   = $serow['acc_no'];
?>

<?php
$id = $_SESSION['SESS_USERID'];

$stmt = $pdo->prepare("SELECT * FROM transactions WHERE log_id = ? ORDER BY id DESC LIMIT 1");
$stmt->execute([$id]);
$serow = $stmt->fetch(PDO::FETCH_ASSOC);

$trans_amount = $serow['trans_amount'];

$cur = $serow['cur'];
?>

<body onpageshow="myFunction()">

<div class="success-card">

    <div class="success-icon">✔</div>

    <div class="success-text">
        Your fund transfer of 
        <strong><?php echo $trans_amount ?> <?php echo $cur ?></strong><br>
        from Account 
        (<span class="acc-number"><?php echo $acc_no ?></span>) 
        was successful.
    </div>

    <div class="loader"></div>

    <div class="redirect-text">
        Processing complete... Redirecting to your account summary.
    </div>

</div>

<meta http-equiv='refresh' content='5; url=account_summary.php' />

<script>
function myFunction() {
    setTimeout(function(){
        alert("Transaction Completed!");
    }, 500);
}
</script>

</body>
</html>