<?php

session_name('small_admin_session');

if (!is_dir(dirname(__DIR__) . '/session_data/small')) { mkdir(dirname(__DIR__) . '/session_data/small', 0700, true); } session_save_path(dirname(__DIR__) . '/session_data/small');

session_set_cookie_params(['path' => '/', 'httponly' => true, 'samesite' => 'Strict']);

session_start();

error_reporting(0);

include('includes/dbconnection.php');

require_once __DIR__ . '/includes/session_term_helper.php';
// Fetch current session and term (with gap/fallback support)
$stResult = resolveCurrentSessionTerm($con);
$currentSessionId   = $stResult['session_id'];
$currentSessionName = $stResult['session_name'];
$currentTermId      = $stResult['term_id'];
$currentTermName    = $stResult['term_name'];
require_once 'vendor/autoload.php';



use Dotenv\Dotenv;



if (empty($_SESSION['sid'])) {

    header('location:logoutsmall.php');

    exit;

}



$student_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

$msg        = '';

$msg_type   = '';

$student    = null;

$wallet     = null;



// -----------------------------------------------------------------------

// No id=  ? show student search form

// -----------------------------------------------------------------------

if ($student_id === 0) {

    $search_results = [];

    $search_query   = '';

    if (isset($_POST['search_student'])) {

        $search_query = trim($_POST['search_query'] ?? '');

        if (!empty($search_query)) {

            $sq = '%' . $search_query . '%';

            $ss = $con->prepare(

                "SELECT s.id, s.studentno, s.studentName, s.class, s.section,

                        COALESCE(w.account_number, '') AS account_number

                 FROM students s

                 LEFT JOIN wallets w ON s.id = w.student_id

                 WHERE s.studentName LIKE ? OR s.studentno LIKE ?

                 ORDER BY s.studentName ASC LIMIT 30"

            );

            $ss->bind_param("ss", $sq, $sq);

            $ss->execute();

            $search_results = $ss->get_result()->fetch_all(MYSQLI_ASSOC);

            $ss->close();

        }

    }

    ?>

<!DOCTYPE html>

<html lang="en">

<head>

    <?php @include("includes/head.php"); ?>



    <style>

        .search-wrapper { max-width: 860px; margin: 0 auto; padding: 0 0 40px; }

        .search-hero {

            background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #1e1b4b 100%);

            border-radius: 20px; padding: 28px 32px; position: relative; overflow: hidden;

            box-shadow: 0 20px 60px rgba(15,23,42,.35); margin-bottom: 24px;

        }

        .search-hero::before {

            content: ''; position: absolute; top: -60px; right: -60px;

            width: 220px; height: 220px;

            background: radial-gradient(circle, rgba(99,102,241,.25) 0%, transparent 70%);

            border-radius: 50%;

        }

        .search-hero-title { font-size: 1.25rem; font-weight: 800; color: #f8fafc; margin: 0 0 4px; }

        .search-hero-sub { font-size: .8rem; color: #94a3b8; margin: 0; }

        .search-hero-icon {

            width: 48px; height: 48px;

            background: linear-gradient(135deg, #6366f1, #4f46e5);

            border-radius: 14px; display: flex; align-items: center; justify-content: center;

            font-size: 1.2rem; color: #fff; flex-shrink: 0;

            box-shadow: 0 8px 20px rgba(99,102,241,.4);

        }

        .search-card { background: #fff; border-radius: 20px; box-shadow: 0 4px 30px rgba(15,23,42,.07); border: 1px solid #e8ecf4; overflow: hidden; }

        .search-card-header { padding: 20px 28px; border-bottom: 1px solid #f1f5f9; display: flex; align-items: center; gap: 10px; }

        .search-card-header-icon { width: 36px; height: 36px; background: linear-gradient(135deg, #0f172a, #1e293b); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: .85rem; }

        .search-card-header h5 { margin: 0; font-size: .95rem; font-weight: 700; color: #0f172a; }

        .search-card-body { padding: 28px; }

        .search-input-wrap { position: relative; }

        .search-input-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: .9rem; pointer-events: none; }

        .search-input { width: 100%; height: 50px; border: 1.5px solid #e2e8f0; border-radius: 14px; padding: 0 140px 0 44px; font-size: .9rem; color: #0f172a; background: #f8fafc; outline: none; transition: border-color .2s, box-shadow .2s; }

        .search-input:focus { border-color: #6366f1; box-shadow: 0 0 0 4px rgba(99,102,241,.1); background: #fff; }

        .search-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); height: 38px; padding: 0 20px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; border: none; font-size: .85rem; font-weight: 600; display: flex; align-items: center; gap: 6px; cursor: pointer; transition: opacity .15s; }

        .search-btn:hover { opacity: .9; }

        .results-table { width: 100%; border-collapse: collapse; margin-top: 20px; }

        .results-table thead tr { background: #f8fafc; }

        .results-table th { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 10px 14px; border-bottom: 1.5px solid #e8ecf4; white-space: nowrap; }

        .results-table td { padding: 12px 14px; border-bottom: 1px solid #f1f5f9; font-size: .88rem; color: #0f172a; vertical-align: middle; }

        .results-table tbody tr:hover { background: #f8fafc; }

        .results-table tbody tr:last-child td { border-bottom: none; }

        .student-name-cell { font-weight: 700; display: flex; align-items: center; gap: 10px; }

        .student-avatar-sm { width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; background: linear-gradient(135deg, #6366f1, #4f46e5); display: flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 800; color: #fff; }

        .gen-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 16px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; font-size: .8rem; font-weight: 600; text-decoration: none; transition: opacity .15s; box-shadow: 0 4px 12px rgba(99,102,241,.3); }

        .gen-btn:hover { opacity: .9; color: #fff; text-decoration: none; }

        .no-results { background: #fffbeb; border: 1.5px solid #fde68a; border-radius: 12px; padding: 14px 18px; font-size: .88rem; color: #92400e; display: flex; align-items: center; gap: 8px; margin-top: 16px; }

    </style>

</head>

<body class="hold-transition sidebar-mini layout-fixed">

<div class="wrapper">

    <?php @include("includes/header3.php"); ?>

    <?php @include("includes/sidebar3.php"); ?>

    <div class="content-wrapper" style="background:#f0f2f8;">



    

<section class="content-header premium-header">

    <div class="container-fluid">

        <div class="header-glass-card">

            <div class="row align-items-center">

                <div class="col-md-8">

                    <div class="title-section">

                        <div class="icon-box bg-primary-gradient shadow-sm">

                            <i class="fas fa-wallet"></i>

                        </div>

                        <div>

                            <h1 class="premium-title text-primary">

                                Wallet Management

                                <span class="premium-subtitle text-secondary">Generate Virtual Account</span>

                            </h1>
                    <div class="mt-1">
                      <?php if ($currentSessionName): ?>
                        <span class="badge badge-primary mr-1">
                          <i class="fas fa-calendar-alt"></i>
                          <?= htmlspecialchars($currentSessionName) ?>
                        </span>
                      <?php endif; ?>
                      <?php if ($currentTermName): ?>
                        <span class="badge badge-success">
                          <i class="fas fa-bookmark"></i>
                          <?= htmlspecialchars($currentTermName) ?>
                        </span>
                      <?php else: ?>
                        <span class="badge badge-warning">
                          <i class="fas fa-exclamation-triangle"></i> No active term
                        </span>
                      <?php endif; ?>
                    </div>

                        </div>

                    </div>

                </div>

                <div class="col-md-4">

                    <nav aria-label="breadcrumb">

                        <ol class="breadcrumb premium-breadcrumb">

                            <li class="breadcrumb-item"><a href="dashboard2.php" class="text-primary">Home</a></li>

                            <li class="breadcrumb-item active" aria-current="page">Virtual Account</li>

                        </ol>

                    </nav>

                </div>

            </div>

        </div>

    </div>

</section>

        <section class="content">

            <div class="container-fluid">

                <div class="row">

                    <div class="col-md-12">

                        <div class="card card-primary">

                            <div class="card-header">

                                <h5 class="card-title font-weight-bold">

                                    <i class="fas fa-university"></i> Generate Virtual Account on Behalf of Student

                                </h5>

                            </div>

                            <div class="card-body">

                                <div class="search-wrapper">

                                    <div class="search-hero">

                                        <div style="display:flex;align-items:center;gap:16px;position:relative;z-index:1;">

                                            <div class="search-hero-icon"><i class="fas fa-university"></i></div>

                                            <div>

                                                <p class="search-hero-title">Generate Student Virtual Account</p>

                                                <p class="search-hero-sub">Search for a student to generate a Paystack dedicated virtual account on their behalf.</p>

                                            </div>

                                        </div>

                                    </div>

                                    <div class="search-card">

                                        <div class="search-card-header">

                                            <div class="search-card-header-icon"><i class="fas fa-search"></i></div>

                                            <h5>Search Student</h5>

                                        </div>

                                        <div class="search-card-body">

                                            <form method="POST">

                                                <div class="search-input-wrap">

                                                    <i class="fas fa-search search-input-icon"></i>

                                                    <input type="text" name="search_query" class="search-input"

                                                           placeholder="Enter student name or admission number"

                                                           value="<?php echo htmlspecialchars($search_query); ?>" required>

                                                    <button type="submit" name="search_student" class="search-btn">

                                                        <i class="fas fa-search"></i> <span>Search</span>

                                                    </button>

                                                </div>

                                            </form>

                                            <?php if (!empty($search_results)): ?>

                                            <div class="table-responsive">

                                                <table class="results-table">

                                                    <thead>

                                                        <tr>

                                                            <th>Student</th>

                                                            <th>Adm No</th>

                                                            <th>Class</th>

                                                            <th>Wallet Status</th>

                                                            <th class="text-center">Action</th>

                                                        </tr>

                                                    </thead>

                                                    <tbody>

                                                        <?php foreach ($search_results as $sr): ?>

                                                        <tr>

                                                            <td>

                                                                <div class="student-name-cell">

                                                                    <div class="student-avatar-sm"><?php echo strtoupper(substr($sr['studentName'], 0, 1)); ?></div>

                                                                    <span><?php echo htmlspecialchars($sr['studentName']); ?></span>

                                                                </div>

                                                            </td>

                                                            <td><?php echo htmlspecialchars($sr['studentno']); ?></td>

                                                            <td><?php echo htmlspecialchars($sr['class'] . ' ' . $sr['section']); ?></td>

                                                            <td>

                                                                <?php if (!empty($sr['account_number'])): ?>

                                                                    <span class="badge badge-success">Active</span>

                                                                <?php else: ?>

                                                                    <span class="badge badge-warning">No Wallet</span>

                                                                <?php endif; ?>

                                                            </td>

                                                            <td class="text-center">

                                                                <a href="?id=<?php echo $sr['id']; ?>" class="gen-btn">

                                                                    <i class="fas fa-university"></i> View

                                                                </a>

                                                            </td>

                                                        </tr>

                                                        <?php endforeach; ?>

                                                    </tbody>

                                                </table>

                                            </div>

                                            <?php elseif (isset($_POST['search_student']) && !empty($search_query)): ?>

                                                <div class="no-results">

                                                    <i class="fas fa-exclamation-triangle"></i>

                                                    No students found for "<?php echo htmlspecialchars($search_query); ?>".

                                                </div>

                                            <?php endif; ?>

                                        </div>

                                    </div>

                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </section>

    </div>

    <?php @include("includes/footer.php"); ?>

    <?php @include("includes/foot.php"); ?>

</div>

</body>

</html>

<?php

    exit;

}



// -----------------------------------------------------------------------

// ?id= present  fetch student and wallet status

// -----------------------------------------------------------------------

$stmt = $con->prepare("SELECT id, studentno, studentName, email, contactno, class, section FROM students WHERE id = ?");

$stmt->bind_param("i", $student_id);

$stmt->execute();

$student = $stmt->get_result()->fetch_assoc();

$stmt->close();



if (!$student) {

    $msg      = "Student not found.";

    $msg_type = "danger";

}



if (empty($msg) && empty($student['email'])) {

    $msg      = "This student has no email address on record. Please update their profile before generating a virtual account.";

    $msg_type = "danger";

}



if (empty($msg)) {

    $wstmt = $con->prepare("SELECT account_number, bank_name, account_name FROM wallets WHERE student_id = ?");

    $wstmt->bind_param("i", $student_id);

    $wstmt->execute();

    $wallet = $wstmt->get_result()->fetch_assoc();

    $wstmt->close();

}



// -----------------------------------------------------------------------

// POST  generate virtual account

// -----------------------------------------------------------------------

if (empty($msg) && isset($_POST['activate'])) {

    // Guard: already has wallet

    if (!empty($wallet['account_number'])) {

        $msg      = "This student already has an active virtual account (" . htmlspecialchars($wallet['account_number']) . ").";

        $msg_type = "warning";

    } else {

        $dotenv = Dotenv::createImmutable(__DIR__);

        $dotenv->load();

        $secret_key = $_ENV['PAYSTACK_SECRET_KEY'];



        $fullName   = trim($student['studentName']);
        $nameParts  = explode(' ', $fullName, 2);
        $firstName  = $nameParts[0];
        $lastName   = $nameParts[1] ?? 'Student';

        // Normalize phone to international format (+234...)
        $rawPhone = trim($student['contactno']);
        if (preg_match('/^0(\d{10})$/', $rawPhone, $m)) {
            $phone = '+234' . $m[1];
        } elseif (preg_match('/^234(\d{10})$/', $rawPhone, $m)) {
            $phone = '+234' . $m[1];
        } else {
            $phone = $rawPhone;
        }

        $emailParts   = explode('@', $student['email']);

        $paystackEmail = $emailParts[0] . '+' . $student_id . '@' . $emailParts[1];



        // Step 1: Create Paystack customer


        $customer_data = [

            "email"      => $paystackEmail,

            "first_name" => $firstName,

            "last_name"  => $lastName,

            "phone"      => $phone

        ];



        $ch = curl_init('https://api.paystack.co/customer');

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($ch, CURLOPT_POST, true);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customer_data));

        curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $secret_key", "Content-Type: application/json"]);



        $cust_response = json_decode(curl_exec($ch), true);



        if (!($cust_response['status'] ?? false)) {

            $msg      = "Paystack Customer Error: " . ($cust_response['message'] ?? 'Unknown error');

            $msg_type = "danger";

        } else {

            $customer_code = $cust_response['data']['customer_code'];

            // Update customer to ensure phone is always set
            $update_data = [
                "first_name" => $firstName,
                "last_name"  => $lastName,
                "phone"      => $phone
            ];
            $ch2 = curl_init("https://api.paystack.co/customer/$customer_code");
            curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, 'PUT');
            curl_setopt($ch2, CURLOPT_POSTFIELDS, json_encode($update_data));
            curl_setopt($ch2, CURLOPT_HTTPHEADER, ["Authorization: Bearer $secret_key", "Content-Type: application/json"]);
            $upd_response = json_decode(curl_exec($ch2), true);
            curl_close($ch2);

            if (!($upd_response['status'] ?? false)) {
                $msg      = "Failed to update customer: " . ($upd_response['message'] ?? 'Unknown error');
                $msg_type = "danger";
            } else {

            // Step 2: Generate dedicated virtual account

            $account_data = [

                "customer"       => $customer_code,

                "preferred_bank" => "wema-bank",

            ];



            curl_setopt($ch, CURLOPT_URL, 'https://api.paystack.co/dedicated_account');

            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($account_data));



            $acc_response = json_decode(curl_exec($ch), true);



            if (!($acc_response['status'] ?? false)) {

                $msg      = "Paystack Virtual Account Error: " . ($acc_response['message'] ?? 'Unknown error');

                $msg_type = "danger";

            } else {

                $bank_name    = $acc_response['data']['bank']['name'];

                $account_no   = $acc_response['data']['account_number'];

                $account_name = $acc_response['data']['account_name'];



                // Step 3: Save to wallets table

                $ins = $con->prepare("

                    INSERT INTO wallets (student_id, customer_code, account_number, bank_name, account_name)

                    VALUES (?, ?, ?, ?, ?)

                    ON DUPLICATE KEY UPDATE account_number = ?, bank_name = ?, account_name = ?, customer_code = ?

                ");

                $ins->bind_param("issssssss", $student_id, $customer_code, $account_no, $bank_name, $account_name, $account_no, $bank_name, $account_name, $customer_code);



                if ($ins->execute()) {

                    $ins->close();

                    $msg      = "Virtual account generated successfully! Account: <strong>$account_no</strong> | Bank: <strong>" . htmlspecialchars($bank_name) . "</strong>";

                    $msg_type = "success";

                    // Refresh wallet data

                    $wstmt2 = $con->prepare("SELECT account_number, bank_name, account_name FROM wallets WHERE student_id = ?");

                    $wstmt2->bind_param("i", $student_id);

                    $wstmt2->execute();

                    $wallet = $wstmt2->get_result()->fetch_assoc();

                    $wstmt2->close();

                } else {

                    $msg      = "Database error saving wallet. Please try again.";

                    $msg_type = "danger";

                }

            } // end acc_response else
            } // end update customer else

        } // end cust_response else

        curl_close($ch);

    }

}

?>

<!DOCTYPE html>

<html lang="en">

<head>

    <?php @include("includes/head.php"); ?>



</head>

<body class="hold-transition sidebar-mini layout-fixed">

<div class="wrapper">

    <?php @include("includes/header3.php"); ?>

    <?php @include("includes/sidebar3.php"); ?>

    <div class="content-wrapper" style="background:#f0f2f8;">

<section class="content-header premium-header">

    <div class="container-fluid">

        <div class="header-glass-card">

            <div class="row align-items-center">

                <div class="col-md-8">

                    <div class="title-section">

                        <div class="icon-box bg-primary-gradient shadow-sm">

                            <i class="fas fa-wallet"></i>

                        </div>

                        <div>

                            <h1 class="premium-title text-primary">

                                Wallet Management

                                <span class="premium-subtitle text-secondary">Generate Virtual Account</span>

                            </h1>
                    <div class="mt-1">
                      <?php if ($currentSessionName): ?>
                        <span class="badge badge-primary mr-1">
                          <i class="fas fa-calendar-alt"></i>
                          <?= htmlspecialchars($currentSessionName) ?>
                        </span>
                      <?php endif; ?>
                      <?php if ($currentTermName): ?>
                        <span class="badge badge-success">
                          <i class="fas fa-bookmark"></i>
                          <?= htmlspecialchars($currentTermName) ?>
                        </span>
                      <?php else: ?>
                        <span class="badge badge-warning">
                          <i class="fas fa-exclamation-triangle"></i> No active term
                        </span>
                      <?php endif; ?>
                    </div>

                        </div>

                    </div>

                </div>

                <div class="col-md-4">

                    <nav aria-label="breadcrumb">

                        <ol class="breadcrumb premium-breadcrumb">

                            <li class="breadcrumb-item"><a href="dashboard2.php" class="text-primary">Home</a></li>

                            <li class="breadcrumb-item active" aria-current="page">Virtual Account</li>

                        </ol>

                    </nav>

                </div>

            </div>

        </div>

    </div>

</section>



        <section class="content">

            <div class="container-fluid">

                <div class="row">

                    <div class="col-md-12">

                        <div class="card card-primary">

                            <div class="card-header">

                                <h5 class="card-title font-weight-bold">

                                    <i class="fas fa-university"></i> Virtual Account Generation

                                </h5>

                            </div>

                            <div class="card-body justify-content-center">



                                <?php if ($msg): ?>

                                <div class="alert alert-<?= htmlspecialchars($msg_type) ?> alert-dismissible rounded-xl">

                                    <button type="button" class="close" data-dismiss="alert">&times;</button>

                                    <?= $msg ?>

                                </div>

                                <?php endif; ?>



                                <?php if ($student && empty(array_filter([$msg], fn($m) => str_contains($m, 'not found') || str_contains($m, 'no email')))): ?>



                                <div class="bg-white rounded-3xl border border-slate-100 shadow-sm p-6 mb-6">

                                    <div class="flex items-center gap-4 mb-4">

                                        <div class="w-14 h-14 bg-indigo-50 text-indigo-600 rounded-2xl flex items-center justify-center text-xl font-black">

                                            <?php echo strtoupper(substr($student['studentName'], 0, 1)); ?>

                                        </div>

                                        <div>

                                            <h3 class="font-black text-slate-800 text-lg"><?php echo htmlspecialchars($student['studentName']); ?></h3>

                                            <p class="text-slate-400 text-xs font-bold uppercase"><?php echo htmlspecialchars($student['studentno']); ?> &bull; <?php echo htmlspecialchars($student['class'] . ' ' . $student['section']); ?></p>

                                        </div>

                                    </div>



                                    <?php if (!empty($wallet['account_number'])): ?>

                                    <div class="bg-emerald-50 border border-emerald-200 rounded-2xl p-5">

                                        <div class="flex items-center gap-3 mb-3">

                                            <i class="fas fa-check-circle text-emerald-500 text-xl"></i>

                                            <p class="font-bold text-emerald-700 text-sm">This student already has an active virtual account.</p>

                                        </div>

                                        <div class="grid grid-cols-1 gap-2 text-sm">

                                            <div><span class="text-slate-400 text-xs font-bold uppercase">Bank</span><p class="font-bold text-slate-800"><?php echo strtoupper(htmlspecialchars($wallet['bank_name'])); ?></p></div>

                                            <div><span class="text-slate-400 text-xs font-bold uppercase">Account Name</span><p class="font-bold text-slate-800"><?php echo strtoupper(htmlspecialchars($wallet['account_name'])); ?></p></div>

                                            <div>

                                                <span class="text-slate-400 text-xs font-bold uppercase">Account Number</span>

                                                <div class="flex items-center gap-3 relative">

                                                    <p id="accNumDisplay" class="font-black text-indigo-600 text-2xl tracking-tighter"><?php echo htmlspecialchars($wallet['account_number']); ?></p>

                                                    <button onclick="copyAccNum()" class="text-slate-400 hover:text-indigo-600 transition-colors accNum" title="Copy account number">

                                                        <i id="copyIcon" class="fas fa-copy text-lg"></i>

                                                    </button>

                                                    <span id="copyToast" class="absolute left-0 -bottom-5 text-[11px] text-emerald-600 font-bold opacity-0 transition-opacity duration-300">Copied!</span>

                                                </div>

                                            </div>

                                        </div>

                                    </div>



                                    <?php else: ?>

                                    <div class="bg-amber-50 border border-amber-200 rounded-2xl p-4 mb-5 text-sm text-amber-800">

                                        <i class="fas fa-exclamation-triangle mr-2 text-amber-500"></i>

                                        This student does not have a virtual account yet. Click below to generate one.

                                    </div>

                                    <form method="POST" action="?id=<?php echo $student_id; ?>">

                                        <button type="submit" name="activate"

                                                class="w-full bg-indigo-600 hover:bg-indigo-700 text-white py-4 rounded-2xl font-bold transition-all flex items-center justify-center gap-2 shadow-lg">

                                            <i class="fas fa-university"></i> Generate Virtual Account

                                        </button>

                                    </form>

                                    <?php endif; ?>

                                </div>



                                <?php endif; ?>



                                <div class="text-center mt-4">

                                    <a href="small_generate_wallet.php" class="text-xs font-bold text-slate-400 hover:text-indigo-600 uppercase tracking-widest transition-colors">

                                        <i class="fas fa-arrow-left mr-1"></i> Search Another Student

                                    </a>

                                </div>



                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </section>

    </div>

    <?php @include("includes/footer.php"); ?>

    <?php @include("includes/foot.php"); ?>

</div>

<script>

function copyAccNum() {

    const num = document.getElementById('accNumDisplay');

    if (!num) return;

    navigator.clipboard.writeText(num.innerText.trim()).then(() => {

        const icon  = document.getElementById('copyIcon');

        const toast = document.getElementById('copyToast');

        icon.classList.replace('fa-copy', 'fa-check');

        toast.style.opacity = '1';

        setTimeout(() => {

            icon.classList.replace('fa-check', 'fa-copy');

            toast.style.opacity = '0';

        }, 2000);

    });

}

</script>

</body>

</html>