<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$pageName = "View Transaction";
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/header.php");

// ============ FETCH TRANSACTION ============
if (!isset($_GET['id']) || empty($_GET['id'])) {
    echo "<script>alert('No transaction ID provided.'); window.location='./transactions.php';</script>";
    exit;
}

$id = $_GET['id'];

$sql = "SELECT 
            t.trans_id,
            t.user_id,
            t.amount,
            t.account_name,
            t.account_number,
            t.bank_name,
            t.bank_country,
            t.account_type,
            t.trans_type,
            t.transaction_type,
            t.trans_status,
            t.refrence_id,
            t.trans_date,
            t.trans_time,
            t.routine_number,
            t.swift_code,
            t.created_at,
            u.id AS uid,
            u.firstname,
            u.lastname,
            u.acct_balance,
            u.acct_email
        FROM transactions t
        LEFT JOIN users u ON t.user_id = u.id
        WHERE t.refrence_id = :id";
$data = $conn->prepare($sql);
$data->execute(['id' => $id]);
$result = $data->fetch(PDO::FETCH_ASSOC);

if (!$result) {
    echo "<script>alert('Transaction not found.'); window.location='./transactions.php';</script>";
    exit;
}

$transStatus = TranStatus($result);
$userId = $result['uid'];
$amount = $result['amount'];
$transType = $result['trans_type'] ?? 'N/A';

// Determine if this is a wire-type transaction (has routing/swift fields)
$isWire = (stripos($transType, 'wire') !== false || stripos($transType, 'interbank') !== false);

// ============ ACCEPT HANDLER ============
if (isset($_POST['accept'])) {
    $status_value = "completed";
    $sql = "UPDATE transactions SET trans_status = :status WHERE refrence_id = :id";
    $stmt = $conn->prepare($sql);
    $stmt->execute(['status' => $status_value, 'id' => $id]);

    // Send email notification
    $full_name = $result['firstname'] . " " . $result['lastname'];
    $user_balance = $result['acct_balance'];
    $APP_NAME = WEB_TITLE;
    $APP_URL = WEB_URL;
    $SITE_ADDRESS = $page['url_address'] ?? '';
    $user_email = $result['acct_email'];
    $trans_status = "completed";

    if ($isWire) {
        $message = $sendMail->AdminWireMsg($full_name, $amount, $user_balance, $trans_status, $transType, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    } else {
        $message = $sendMail->AdminDomMsg($full_name, $amount, $user_balance, $trans_status, $transType, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    }
    $subject = $transType . " - " . $APP_NAME;
    $email_message->send_mail($user_email, $message, $subject);

    $msg1 = "
    <div class='alert alert-success'>
        <script type='text/javascript'>
            function Redirect() { window.location='./transactions.php'; }
            setTimeout('Redirect()', 3000);
        </script>
        <center><img src='../assets/images/loading.gif' width='180px' /></center>
        <center><strong style='color:black;'>Transaction approved successfully. Redirecting...</strong></center>
    </div>";
}

// ============ DECLINE HANDLER ============
if (isset($_POST['decline'])) {
    $status_value = "failed";
    $sql = "UPDATE transactions SET trans_status = :status WHERE refrence_id = :id";
    $stmt = $conn->prepare($sql);
    $stmt->execute(['status' => $status_value, 'id' => $id]);

    // Refund balance
    $amount_balance = $result['acct_balance'] + $result['amount'];
    $sql = "UPDATE users SET acct_balance = :acct_balance WHERE id = :id";
    $stmt = $conn->prepare($sql);
    $stmt->execute(['acct_balance' => $amount_balance, 'id' => $userId]);

    // Send email notification
    $full_name = $result['firstname'] . " " . $result['lastname'];
    $user_balance = $result['acct_balance'];
    $APP_NAME = WEB_TITLE;
    $APP_URL = WEB_URL;
    $SITE_ADDRESS = $page['url_address'] ?? '';
    $user_email = $result['acct_email'];
    $trans_status = "failed";

    if ($isWire) {
        $message = $sendMail->AdminWireMsg($full_name, $amount, $user_balance, $trans_status, $transType, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    } else {
        $message = $sendMail->AdminDomMsg($full_name, $amount, $user_balance, $trans_status, $transType, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    }
    $subject = $transType . " - " . $APP_NAME;
    $email_message->send_mail($user_email, $message, $subject);

    $msg1 = "
    <div class='alert alert-danger'>
        <script type='text/javascript'>
            function Redirect() { window.location='./transactions.php'; }
            setTimeout('Redirect()', 3000);
        </script>
        <center><img src='../assets/images/loading.gif' width='180px' /></center>
        <center><strong style='color:black;'>Transaction declined. Balance refunded. Redirecting...</strong></center>
    </div>";
}

// ============ HOLD HANDLER ============
if (isset($_POST['hold'])) {
    $status_value = "processing";
    $sql = "UPDATE transactions SET trans_status = :status WHERE refrence_id = :id";
    $stmt = $conn->prepare($sql);
    $stmt->execute(['status' => $status_value, 'id' => $id]);

    // Send email notification
    $full_name = $result['firstname'] . " " . $result['lastname'];
    $user_balance = $result['acct_balance'];
    $APP_NAME = WEB_TITLE;
    $APP_URL = WEB_URL;
    $SITE_ADDRESS = $page['url_address'] ?? '';
    $user_email = $result['acct_email'];
    $trans_status = "processing";

    if ($isWire) {
        $message = $sendMail->AdminWireMsg($full_name, $amount, $user_balance, $trans_status, $transType, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    } else {
        $message = $sendMail->AdminDomMsg($full_name, $amount, $user_balance, $trans_status, $transType, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    }
    $subject = $transType . " - " . $APP_NAME;
    $email_message->send_mail($user_email, $message, $subject);

    $msg1 = "
    <div class='alert alert-warning'>
        <script type='text/javascript'>
            function Redirect() { window.location='./transactions.php'; }
            setTimeout('Redirect()', 3000);
        </script>
        <center><img src='../assets/images/loading.gif' width='180px' /></center>
        <center><strong style='color:black;'>Transaction placed on hold. Redirecting...</strong></center>
    </div>";
}

// ============ UPDATE HANDLER ============
if (isset($_POST['update_trans'])) {
    $upd_amount = $_POST['amount'];
    $upd_account_name = $_POST['account_name'];
    $upd_bank_name = $_POST['bank_name'];
    $upd_account_number = $_POST['account_number'];
    $upd_account_type = $_POST['account_type'];
    $upd_bank_country = $_POST['bank_country'];
    $upd_created_at = $_POST['created_at'];

    // Base fields
    $updateFields = "amount = :amount, bank_name = :bank_name, account_name = :account_name, account_number = :account_number, account_type = :account_type, bank_country = :bank_country, created_at = :created_at";
    $updateParams = [
        'amount' => $upd_amount,
        'bank_name' => $upd_bank_name,
        'account_name' => $upd_account_name,
        'account_number' => $upd_account_number,
        'account_type' => $upd_account_type,
        'bank_country' => $upd_bank_country,
        'created_at' => $upd_created_at,
        'id' => $id
    ];

    // Add wire-specific fields if present
    if (!empty($_POST['routine_number']) || !empty($_POST['swift_code'])) {
        $updateFields .= ", routine_number = :routine_number, swift_code = :swift_code";
        $updateParams['routine_number'] = $_POST['routine_number'] ?? '';
        $updateParams['swift_code'] = $_POST['swift_code'] ?? '';
    }

    $sql = "UPDATE transactions SET $updateFields WHERE refrence_id = :id";
    $stmt = $conn->prepare($sql);
    $stmt->execute($updateParams);

    $msg1 = "
    <div class='alert alert-success'>
        <script type='text/javascript'>
            function Redirect() { window.location='./transactions.php'; }
            setTimeout('Redirect()', 3000);
        </script>
        <center><img src='../assets/images/loading.gif' width='180px' /></center>
        <center><strong style='color:black;'>Transaction updated successfully. Redirecting...</strong></center>
    </div>";
}

// Re-fetch after any update so the form shows current data
if (isset($_POST['accept']) || isset($_POST['decline']) || isset($_POST['hold']) || isset($_POST['update_trans'])) {
    $data = $conn->prepare("SELECT 
            t.trans_id, t.user_id, t.amount, t.account_name, t.account_number,
            t.bank_name, t.bank_country, t.account_type, t.trans_type, t.transaction_type,
            t.trans_status, t.refrence_id, t.trans_date, t.trans_time,
            t.routine_number, t.swift_code, t.created_at,
            u.id AS uid, u.firstname, u.lastname, u.acct_balance, u.acct_email
        FROM transactions t
        LEFT JOIN users u ON t.user_id = u.id
        WHERE t.refrence_id = :id");
    $data->execute(['id' => $id]);
    $result = $data->fetch(PDO::FETCH_ASSOC);
    $transStatus = TranStatus($result);
}

// Status badge for display
$statusRaw = strtolower($result['trans_status'] ?? '');
$statusBadges = [
    'completed' => '<span class="label label-success">Completed</span>',
    'approved'  => '<span class="label label-success">Approved</span>',
    'pending'   => '<span class="label label-warning">Pending</span>',
    'processing'=> '<span class="label label-info">Processing</span>',
    'failed'    => '<span class="label label-danger">Failed</span>',
];
$statusBadge = $statusBadges[$statusRaw] ?? '<span class="label label-default">' . htmlspecialchars($result['trans_status'] ?? 'Unknown') . '</span>';

// Direction badge
$direction = strtolower($result['transaction_type'] ?? '');
if ($direction == 'credit') {
    $dirBadge = '<span class="label label-success">Credit</span>';
} elseif ($direction == 'debit') {
    $dirBadge = '<span class="label label-danger">Debit</span>';
} else {
    $dirBadge = '<span class="label label-default">' . htmlspecialchars($result['transaction_type'] ?? 'N/A') . '</span>';
}

?>

<!-- Content Wrapper -->
<div class="content-wrapper">
    <!-- Content Header -->
    <section class="content-header">
        <h1>
            View Transaction
            <small><?= htmlspecialchars($result['refrence_id'] ?? '') ?></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="./dashboard.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="./transactions.php">All Transactions</a></li>
            <li class="active">View</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <?php if (isset($msg1)) echo $msg1; ?>

        <!-- Transaction Summary -->
        <div class="row">
            <div class="col-md-4 col-sm-6">
                <div class="info-box">
                    <span class="info-box-icon bg-aqua"><i class="fa fa-exchange"></i></span>
                    <div class="info-box-content">
                        <span class="info-box-text">Transaction Type</span>
                        <span class="info-box-number"><?= htmlspecialchars($transType) ?></span>
                    </div>
                </div>
            </div>
            <div class="col-md-4 col-sm-6">
                <div class="info-box">
                    <span class="info-box-icon bg-green"><i class="fa fa-money"></i></span>
                    <div class="info-box-content">
                        <span class="info-box-text">Amount</span>
                        <span class="info-box-number"><?= number_format((float)$result['amount'], 2) ?></span>
                    </div>
                </div>
            </div>
            <div class="col-md-4 col-sm-6">
                <div class="info-box">
                    <span class="info-box-icon bg-yellow"><i class="fa fa-flag"></i></span>
                    <div class="info-box-content">
                        <span class="info-box-text">Status</span>
                        <span class="info-box-number"><?= $statusBadge ?></span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Transaction Details (Read-Only) -->
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title"><i class="fa fa-info-circle"></i> Transaction Details</h3>
            </div>
            <div class="box-body">
                <div class="row">
                    <div class="col-md-6">
                        <table class="table table-striped">
                            <tr><th>Reference ID</th><td><?= htmlspecialchars($result['refrence_id'] ?? '') ?></td></tr>
                            <tr><th>User</th><td><?= htmlspecialchars(($result['firstname'] ?? '') . ' ' . ($result['lastname'] ?? '')) ?></td></tr>
                            <tr><th>Direction</th><td><?= $dirBadge ?></td></tr>
                            <tr><th>Date</th><td><?= htmlspecialchars($result['trans_date'] ?? '') ?></td></tr>
                            <tr><th>Time</th><td><?= htmlspecialchars($result['trans_time'] ?? '') ?></td></tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table class="table table-striped">
                            <tr><th>Account Name</th><td><?= htmlspecialchars($result['account_name'] ?? 'N/A') ?></td></tr>
                            <tr><th>Account Number</th><td><?= htmlspecialchars($result['account_number'] ?? 'N/A') ?></td></tr>
                            <tr><th>Bank Name</th><td><?= htmlspecialchars($result['bank_name'] ?? 'N/A') ?></td></tr>
                            <tr><th>Bank Country</th><td><?= htmlspecialchars($result['bank_country'] ?? 'N/A') ?></td></tr>
                            <?php if ($isWire): ?>
                            <tr><th>Routine Number</th><td><?= htmlspecialchars($result['routine_number'] ?? 'N/A') ?></td></tr>
                            <tr><th>Swift Code</th><td><?= htmlspecialchars($result['swift_code'] ?? 'N/A') ?></td></tr>
                            <?php endif; ?>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Edit Transaction Form -->
        <div class="box box-default">
            <div class="box-header with-border">
                <h3 class="box-title"><i class="fa fa-pencil"></i> Edit Transaction</h3>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                </div>
            </div>
            <form method="POST">
                <div class="box-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Amount</label>
                                <input type="number" step="0.01" class="form-control" name="amount" value="<?= htmlspecialchars($result['amount'] ?? '') ?>" required>
                            </div>
                            <div class="form-group">
                                <label>Bank Name</label>
                                <input type="text" class="form-control" name="bank_name" value="<?= htmlspecialchars($result['bank_name'] ?? '') ?>" required>
                            </div>
                            <div class="form-group">
                                <label>Account Number</label>
                                <input type="text" inputmode="numeric" pattern="[0-9]+" maxlength="20" autocomplete="off" class="form-control" name="account_number" value="<?= htmlspecialchars($result['account_number'] ?? '') ?>" required>
                            </div>
                            <?php if ($isWire): ?>
                            <div class="form-group">
                                <label>Routine Number</label>
                                <input type="text" inputmode="numeric" maxlength="12" autocomplete="off" class="form-control" name="routine_number" value="<?= htmlspecialchars($result['routine_number'] ?? '') ?>">
                            </div>
                            <?php endif; ?>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Account Name</label>
                                <input type="text" class="form-control" name="account_name" value="<?= htmlspecialchars($result['account_name'] ?? '') ?>" required>
                            </div>
                            <?php if ($isWire): ?>
                            <div class="form-group">
                                <label>Swift Code</label>
                                <input type="text" maxlength="12" autocomplete="off" class="form-control" name="swift_code" value="<?= htmlspecialchars($result['swift_code'] ?? '') ?>">
                            </div>
                            <?php endif; ?>
                            <div class="form-group">
                                <label>Bank Country</label>
                                <select name="bank_country" required class="form-control">
                                    <option value="<?= htmlspecialchars($result['bank_country'] ?? '') ?>"><?= htmlspecialchars($result['bank_country'] ?? 'Select Country') ?></option>
                                    <option value="Afganistan">Afghanistan</option>
                                    <option value="Albania">Albania</option>
                                    <option value="Algeria">Algeria</option>
                                    <option value="American Samoa">American Samoa</option>
                                    <option value="Andorra">Andorra</option>
                                    <option value="Angola">Angola</option>
                                    <option value="Anguilla">Anguilla</option>
                                    <option value="Antigua & Barbuda">Antigua & Barbuda</option>
                                    <option value="Argentina">Argentina</option>
                                    <option value="Armenia">Armenia</option>
                                    <option value="Aruba">Aruba</option>
                                    <option value="Australia">Australia</option>
                                    <option value="Austria">Austria</option>
                                    <option value="Azerbaijan">Azerbaijan</option>
                                    <option value="Bahamas">Bahamas</option>
                                    <option value="Bahrain">Bahrain</option>
                                    <option value="Bangladesh">Bangladesh</option>
                                    <option value="Barbados">Barbados</option>
                                    <option value="Belarus">Belarus</option>
                                    <option value="Belgium">Belgium</option>
                                    <option value="Belize">Belize</option>
                                    <option value="Benin">Benin</option>
                                    <option value="Bermuda">Bermuda</option>
                                    <option value="Bhutan">Bhutan</option>
                                    <option value="Bolivia">Bolivia</option>
                                    <option value="Bonaire">Bonaire</option>
                                    <option value="Bosnia & Herzegovina">Bosnia & Herzegovina</option>
                                    <option value="Botswana">Botswana</option>
                                    <option value="Brazil">Brazil</option>
                                    <option value="Brunei">Brunei</option>
                                    <option value="Bulgaria">Bulgaria</option>
                                    <option value="Burkina Faso">Burkina Faso</option>
                                    <option value="Burundi">Burundi</option>
                                    <option value="Cambodia">Cambodia</option>
                                    <option value="Cameroon">Cameroon</option>
                                    <option value="Canada">Canada</option>
                                    <option value="Cape Verde">Cape Verde</option>
                                    <option value="Cayman Islands">Cayman Islands</option>
                                    <option value="Central African Republic">Central African Republic</option>
                                    <option value="Chad">Chad</option>
                                    <option value="Chile">Chile</option>
                                    <option value="China">China</option>
                                    <option value="Colombia">Colombia</option>
                                    <option value="Congo">Congo</option>
                                    <option value="Costa Rica">Costa Rica</option>
                                    <option value="Croatia">Croatia</option>
                                    <option value="Cuba">Cuba</option>
                                    <option value="Cyprus">Cyprus</option>
                                    <option value="Czech Republic">Czech Republic</option>
                                    <option value="Denmark">Denmark</option>
                                    <option value="Dominican Republic">Dominican Republic</option>
                                    <option value="Ecuador">Ecuador</option>
                                    <option value="Egypt">Egypt</option>
                                    <option value="El Salvador">El Salvador</option>
                                    <option value="Estonia">Estonia</option>
                                    <option value="Ethiopia">Ethiopia</option>
                                    <option value="Fiji">Fiji</option>
                                    <option value="Finland">Finland</option>
                                    <option value="France">France</option>
                                    <option value="Gabon">Gabon</option>
                                    <option value="Gambia">Gambia</option>
                                    <option value="Georgia">Georgia</option>
                                    <option value="Germany">Germany</option>
                                    <option value="Ghana">Ghana</option>
                                    <option value="Greece">Greece</option>
                                    <option value="Guatemala">Guatemala</option>
                                    <option value="Guinea">Guinea</option>
                                    <option value="Guyana">Guyana</option>
                                    <option value="Haiti">Haiti</option>
                                    <option value="Honduras">Honduras</option>
                                    <option value="Hong Kong">Hong Kong</option>
                                    <option value="Hungary">Hungary</option>
                                    <option value="Iceland">Iceland</option>
                                    <option value="India">India</option>
                                    <option value="Indonesia">Indonesia</option>
                                    <option value="Iran">Iran</option>
                                    <option value="Iraq">Iraq</option>
                                    <option value="Ireland">Ireland</option>
                                    <option value="Israel">Israel</option>
                                    <option value="Italy">Italy</option>
                                    <option value="Jamaica">Jamaica</option>
                                    <option value="Japan">Japan</option>
                                    <option value="Jordan">Jordan</option>
                                    <option value="Kazakhstan">Kazakhstan</option>
                                    <option value="Kenya">Kenya</option>
                                    <option value="Kuwait">Kuwait</option>
                                    <option value="Latvia">Latvia</option>
                                    <option value="Lebanon">Lebanon</option>
                                    <option value="Liberia">Liberia</option>
                                    <option value="Libya">Libya</option>
                                    <option value="Lithuania">Lithuania</option>
                                    <option value="Luxembourg">Luxembourg</option>
                                    <option value="Madagascar">Madagascar</option>
                                    <option value="Malaysia">Malaysia</option>
                                    <option value="Malawi">Malawi</option>
                                    <option value="Mali">Mali</option>
                                    <option value="Malta">Malta</option>
                                    <option value="Mexico">Mexico</option>
                                    <option value="Moldova">Moldova</option>
                                    <option value="Monaco">Monaco</option>
                                    <option value="Mongolia">Mongolia</option>
                                    <option value="Morocco">Morocco</option>
                                    <option value="Mozambique">Mozambique</option>
                                    <option value="Myanmar">Myanmar</option>
                                    <option value="Nepal">Nepal</option>
                                    <option value="Netherlands">Netherlands</option>
                                    <option value="New Zealand">New Zealand</option>
                                    <option value="Nicaragua">Nicaragua</option>
                                    <option value="Niger">Niger</option>
                                    <option value="Nigeria">Nigeria</option>
                                    <option value="Norway">Norway</option>
                                    <option value="Oman">Oman</option>
                                    <option value="Pakistan">Pakistan</option>
                                    <option value="Palestine">Palestine</option>
                                    <option value="Panama">Panama</option>
                                    <option value="Papua New Guinea">Papua New Guinea</option>
                                    <option value="Paraguay">Paraguay</option>
                                    <option value="Peru">Peru</option>
                                    <option value="Phillipines">Philippines</option>
                                    <option value="Poland">Poland</option>
                                    <option value="Portugal">Portugal</option>
                                    <option value="Puerto Rico">Puerto Rico</option>
                                    <option value="Qatar">Qatar</option>
                                    <option value="Romania">Romania</option>
                                    <option value="Russia">Russia</option>
                                    <option value="Rwanda">Rwanda</option>
                                    <option value="Saudi Arabia">Saudi Arabia</option>
                                    <option value="Senegal">Senegal</option>
                                    <option value="Sierra Leone">Sierra Leone</option>
                                    <option value="Singapore">Singapore</option>
                                    <option value="Slovakia">Slovakia</option>
                                    <option value="Slovenia">Slovenia</option>
                                    <option value="Somalia">Somalia</option>
                                    <option value="South Africa">South Africa</option>
                                    <option value="Spain">Spain</option>
                                    <option value="Sri Lanka">Sri Lanka</option>
                                    <option value="Sudan">Sudan</option>
                                    <option value="Sweden">Sweden</option>
                                    <option value="Switzerland">Switzerland</option>
                                    <option value="Syria">Syria</option>
                                    <option value="Taiwan">Taiwan</option>
                                    <option value="Tanzania">Tanzania</option>
                                    <option value="Thailand">Thailand</option>
                                    <option value="Togo">Togo</option>
                                    <option value="Trinidad & Tobago">Trinidad & Tobago</option>
                                    <option value="Tunisia">Tunisia</option>
                                    <option value="Turkey">Turkey</option>
                                    <option value="Uganda">Uganda</option>
                                    <option value="Ukraine">Ukraine</option>
                                    <option value="United Arab Erimates">United Arab Emirates</option>
                                    <option value="United Kingdom">United Kingdom</option>
                                    <option value="United States of America">United States of America</option>
                                    <option value="Uruguay">Uruguay</option>
                                    <option value="Uzbekistan">Uzbekistan</option>
                                    <option value="Venezuela">Venezuela</option>
                                    <option value="Vietnam">Vietnam</option>
                                    <option value="Yemen">Yemen</option>
                                    <option value="Zambia">Zambia</option>
                                    <option value="Zimbabwe">Zimbabwe</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>Account Type</label>
                                <select name="account_type" required class="form-control">
                                    <option value="<?= htmlspecialchars($result['account_type'] ?? '') ?>"><?= htmlspecialchars($result['account_type'] ?? 'Select Account Type') ?></option>
                                    <option value="Savings">Savings Account</option>
                                    <option value="Current">Current Account</option>
                                    <option value="Checking">Checking Account</option>
                                    <option value="Fixed Deposit">Fixed Deposit</option>
                                    <option value="Non Resident">Non Resident Account</option>
                                    <option value="Online Banking">Online Banking</option>
                                    <option value="Domicilary Account">Domicilary Account</option>
                                    <option value="Joint Account">Joint Account</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>Date</label>
                                <input type="text" class="form-control" name="created_at" value="<?= htmlspecialchars($result['created_at'] ?? '') ?>" required>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-footer">
                    <button type="submit" name="update_trans" class="btn btn-primary"><i class="fa fa-save"></i> Update</button>
                    <button type="submit" name="accept" class="btn btn-success" onclick="return confirm('Approve this transaction?');"><i class="fa fa-check"></i> Accept</button>
                    <button type="submit" name="hold" class="btn btn-warning" onclick="return confirm('Place this transaction on hold?');"><i class="fa fa-pause"></i> Hold</button>
                    <button type="submit" name="decline" class="btn btn-danger" onclick="return confirm('Decline and refund this transaction?');"><i class="fa fa-times"></i> Decline</button>
                    <a href="./transactions.php" class="btn btn-default pull-right"><i class="fa fa-arrow-left"></i> Back to Transactions</a>
                </div>
            </form>
        </div>

    </section>
</div>

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/footer.php");
?>