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

include("check_installation.php");
//include("../config/theconfig.php");

include("fetch_settings.php");

if (!isset($_SESSION["adminid"])) {
    header("Location: login.php");
    exit;
}

// Handle form submissions first
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $custid = isset($_POST['custid']) ? intval($_POST['custid']) : 0;
    $hide_id = isset($_POST['hide_id']) ? intval($_POST['hide_id']) : 0;

    if (isset($_POST["Del"])) {
        $stmt_del_cust = $con->prepare("DELETE FROM customers WHERE customerid = ?");
        $stmt_del_cust->bind_param('i', $custid);
        $stmt_del_cust->execute();
        $stmt_del_cust->close();

        $stmt_del_acc = $con->prepare("DELETE FROM accounts WHERE customerid = ?");
        $stmt_del_acc->bind_param('i', $custid);
        $stmt_del_acc->execute();
        $stmt_del_acc->close();
        
        $_SESSION['message'] = ['type' => 'success', 'text' => 'Customer account has been successfully deleted.'];
        header("Location: manage_customers.php");
        exit;
    }

    if (isset($_POST["blockcustomer"])) {
        $stmt_block = $con->prepare("UPDATE customers SET accstatus = 'blocked' WHERE customerid = ?");
        $stmt_block->bind_param('i', $hide_id);
        $stmt_block->execute();
        $stmt_block->close();
		
		$stmt_block_acc = $con->prepare("UPDATE accounts SET accstatus = 'blocked' WHERE customerid = ?");
    $stmt_block_acc->bind_param('i', $hide_id);
    $stmt_block_acc->execute();
    $stmt_block_acc->close();
		
        
        $_SESSION['message'] = ['type' => 'success', 'text' => 'Customer account has been (blocked).'];
        header("Location: customer_details.php?custid=" . $hide_id);
        exit;
    }

    if (isset($_POST["unblockcustomer"])) {
    $stmt_unblock = $con->prepare("UPDATE customers SET accstatus = 'active' WHERE customerid = ?");
    $stmt_unblock->bind_param('i', $hide_id);
    $stmt_unblock->execute();
    $stmt_unblock->close();
	
	$stmt_unblock_acc = $con->prepare("UPDATE accounts SET accstatus = 'active' WHERE customerid = ?");
    $stmt_unblock_acc->bind_param('i', $hide_id);
    $stmt_unblock_acc->execute();
    $stmt_unblock_acc->close();

    // Fetch customer details to send email
    $customer_details = null;
    $stmt_email = $con->prepare("SELECT firstname, lastname, email FROM customers WHERE customerid = ? LIMIT 1");
    $stmt_email->bind_param('i', $hide_id);
    $stmt_email->execute();
    $result_email = $stmt_email->get_result();
    if ($result_email->num_rows > 0) {
        $customer_details = $result_email->fetch_assoc();
    }
    $stmt_email->close();
    
    
    $brand_color = '#4f46e5'; 

    if ($customer_details) {
        $custname = htmlspecialchars($customer_details['firstname'] . " " . $customer_details['lastname']);
        $to = $customer_details['email'];
        $subject = 'Account Re-Activated - You can now log in'; 
        
        $message = '
<html>
    <head>
        <meta name="viewport" content="width=device-width">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="https://fonts.googleapis.com/css2?family=Mulish:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
        <title>Account Re-Activation</title>
    </head>
    <body style="background-color: #f6f6f6; font-family: sans-serif; -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.4; margin: 0; padding: 0; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">
        <span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">Your account has been successfully unblocked and is active.</span>
        <table border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background-color: #f6f6f6;">
            <tr>
                <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">&nbsp;</td>
                <td class="container" style="font-family: sans-serif; font-size: 14px; vertical-align: top; display: block; Margin: 0 auto; max-width: 580px; padding: 10px; width: 580px;">
                    <div class="content" style="box-sizing: border-box; display: block; Margin: 0 auto; max-width: 580px; padding: 10px;">
                        <table class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background: #ffffff; border-radius: 3px;">
                            <tr>
                                <td class="wrapper" style="font-family: sans-serif; font-size: 14px; vertical-align: top; box-sizing: border-box; padding: 20px;">
                                    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
                                        <tr>
                                            <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">
                                                <p style="font-family: \'Mulish\', sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Hello ' . $custname . ',</p>
                                                <p style="font-family: \'Mulish\', sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">We are pleased to inform you that your account is now **active** again. Any restrictions or blocks on your access have been removed.</p>
                                                <p style="font-family: \'Mulish\', sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">You can now log in to your account using your existing credentials and resume using all our services.</p>
                                                
                                                <p style="font-family: \'Mulish\', sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Thank you for your patience and for choosing us.</p>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                        <div class="footer" style="clear: both; margin-top: 10px; text-align: center; width: 100%;">
                            <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
                                <tr>
                                    <td class="content-block" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; font-size: 12px; color: #999999; text-align: center;">
                                        <span class="apple-link" style="color: #999999; font-size: 12px; text-align: center;">© ' . date("Y") . ' ' . htmlspecialchars($system_bank_name) . ' (RC796975). All rights reserved.</span>
                                        <br>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="content-block powered-by" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; font-size: 12px; color: #999999; text-align: center;">
                                        All deposits are insured by the Sweden Deposit Insurance Corporation (USDIC). ' . htmlspecialchars($system_bank_name) . ' is licensed by the Federal Rserve System. “' . htmlspecialchars($system_bank_name) . '” and “' . htmlspecialchars($system_bank_name) . '” are trademarks of Offshorehorizon Technologies LTD. Marietorp Solliden 13, Ormaryd 571 72..
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </td>
                <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">&nbsp;</td>
            </tr>
        </table>
    </body>
</html>
';
        
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= "From: " . htmlspecialchars($system_bank_name) . " <" . htmlspecialchars($system_email) . ">" . "\r\n";
        
        
        mail($to, $subject, $message, $headers);
        
    }

    $_SESSION['message'] = ['type' => 'success', 'text' => 'Customer account has been unblocked..']; 
    header("Location: customer_details.php?custid=" . $hide_id);
    exit;
}
    
    
   if (isset($_POST["approve_customer"])) {
    // Check the current status to prevent accidental approval
    $stmt_check_status = $con->prepare("SELECT accstatus, firstname, lastname, email FROM customers WHERE customerid = ? LIMIT 1");
    $stmt_check_status->bind_param('i', $hide_id);
    $stmt_check_status->execute();
    $result_check = $stmt_check_status->get_result();
    $customer_details = $result_check->fetch_assoc();
    $stmt_check_status->close();

    if ($customer_details && trim($customer_details['accstatus']) == 'onreview') {
        // 1. Update the status in the `customers` table
        $stmt_approve_cust = $con->prepare("UPDATE customers SET accstatus = 'active' WHERE customerid = ?");
        $stmt_approve_cust->bind_param('i', $hide_id);
        $stmt_approve_cust->execute();
        $stmt_approve_cust->close();

        // 2. Update the status in the `accounts` table
        $stmt_approve_acc = $con->prepare("UPDATE accounts SET accstatus = 'active' WHERE customerid = ?");
        $stmt_approve_acc->bind_param('i', $hide_id);
        $stmt_approve_acc->execute();
        $stmt_approve_acc->close();

        // 3. Fetch system settings for email
        $stmt_settings = $con->prepare("SELECT bank_name, email FROM system_settings LIMIT 1");
        $stmt_settings->execute();
        $stmt_settings->bind_result($system_bank_name, $system_email);
        $stmt_settings->fetch();
        $stmt_settings->close();
        
        // 4. Prepare and send the email
        $custname = htmlspecialchars($customer_details['firstname'] . " " . $customer_details['lastname']);
        $to = $customer_details['email'];
        $subject = 'Account Approved';

        $message = '
        <html>
            <head>
                <meta name="viewport" content="width=device-width">
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <link href="https://fonts.googleapis.com/css2?family=Mulish:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
                <title>Account Approved</title>
            </head>
            <body style="background-color: #f6f6f6; font-family: sans-serif; -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.4; margin: 0; padding: 0; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">
                <span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">Your account has been approved and is now active.</span>
                <table border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background-color: #f6f6f6;">
                    <tr>
                        <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">&nbsp;</td>
                        <td class="container" style="font-family: sans-serif; font-size: 14px; vertical-align: top; display: block; margin: 0 auto; max-width: 580px; padding: 10px; width: 580px;">
                            <div class="content" style="box-sizing: border-box; display: block; margin: 0 auto; max-width: 580px; padding: 10px;">
                                <table class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background: #ffffff; border-radius: 3px;">
                                    <tr>
                                        <td class="wrapper" style="font-family: sans-serif; font-size: 14px; vertical-align: top; box-sizing: border-box; padding: 20px;">
                                            <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
                                                <tr>
                                                    <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">
                                                        <p style="font-family: \'Mulish\', sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Hello ' . $custname . ',</p>
                                                        <p style="font-family: \'Mulish\', sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">We are pleased to inform you that your account has been approved and is now active. You can now log in and start using our services.</p>
                                                        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
                                                            <tbody>
                                                                <tr>
                                                                    <td align="center" style="font-family: sans-serif; font-size: 14px; vertical-align: top; padding-bottom: 15px;">
                                                                        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: auto;">
                                                                            <tbody>
                                                                                <tr>
                                                                                    <td style="font-family: sans-serif; font-size: 14px; vertical-align: top; background-color: #4f46e5; border-radius: 5px; text-align: center;"> 
                                                                                        <a href="https://ApexRaysFinance.com/user/customer/login.php" target="_blank" style="display: inline-block; color: #ffffff; background-color: #4f46e5; border: solid 1px #4f46e5; border-radius: 5px; box-sizing: border-box; cursor: pointer; text-decoration: none; font-size: 14px; font-weight: bold; margin: 0; padding: 12px 25px; text-transform: capitalize; border-color: #4f46e5;">Log in to your account</a> 
                                                                                    </td>
                                                                                </tr>
                                                                            </tbody>
                                                                        </table>
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                        <p style="font-family: \'Mulish\', sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Thank you for choosing us.</p>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                                <div class="footer" style="clear: both; margin-top: 10px; text-align: center; width: 100%;">
                                    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
                                        <tr>
                                            <td class="content-block" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; font-size: 12px; color: #999999; text-align: center;">
                                                <span class="apple-link" style="color: #999999; font-size: 12px; text-align: center;">© ' . date("Y") . ' ' . htmlspecialchars($system_bank_name) . ' (RC796975). All rights reserved.</span>
                                                <br>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="content-block powered-by" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; font-size: 12px; color: #999999; text-align: center;">
                                                All deposits are insured by the Sweden Deposit Insurance Corporation (USDIC). ' . htmlspecialchars($system_bank_name) . ' is licensed by the Federal Rserve System. “' . htmlspecialchars($system_bank_name) . '” and “' . htmlspecialchars($system_bank_name) . '” are trademarks of Offshorehorizon Technologies LTD. Marietorp Solliden 13, Ormaryd 571 72..
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </td>
                        <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">&nbsp;</td>
                    </tr>
                </table>
            </body>
        </html>
        ';
        
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= "From: " . htmlspecialchars($system_bank_name) . " <" . htmlspecialchars($system_email) . ">" . "\r\n";
        
         mail($to, $subject, $message, $headers); 
        
        $_SESSION['message'] = ['type' => 'success', 'text' => 'Customer account has been approved. An email has been sent.'];
    } else {
        $_SESSION['message'] = ['type' => 'error', 'text' => 'Account cannot be approved. It is not in "onreview" status.'];
    }
    header("Location: customer_details.php?custid=" . $hide_id);
    exit;
}
}

// Fetch customer details
$custid = isset($_GET['custid']) ? intval($_GET['custid']) : 0;
$customer = [];
$accounts = [];

if ($custid > 0) {
    $stmt_cust = $con->prepare("SELECT * FROM customers WHERE customerid = ?");
    $stmt_cust->bind_param('i', $custid);
    $stmt_cust->execute();
    $result_cust = $stmt_cust->get_result();
    if ($result_cust->num_rows > 0) {
        $customer = $result_cust->fetch_assoc();
    }
    $stmt_cust->close();

    // Fetch customer's accounts
    $stmt_acc = $con->prepare("SELECT * FROM accounts WHERE customerid = ?");
    $stmt_acc->bind_param('i', $custid);
    $stmt_acc->execute();
    $result_acc = $stmt_acc->get_result();
    while ($row_acc = $result_acc->fetch_assoc()) {
        $accounts[] = $row_acc;
    }
    $stmt_acc->close();
}

$custname = isset($customer['firstname']) ? htmlspecialchars($customer['firstname'] . " " . $customer['lastname']) : '';
$ifsccode = isset($customer['ifsccode']) ? htmlspecialchars($customer['ifsccode']) : '';
$loginid = isset($customer['loginid']) ? htmlspecialchars($customer['loginid']) : '';
$accstatus = isset($customer['accstatus']) ? trim(htmlspecialchars($customer['accstatus'])) : '';
$city = isset($customer['city']) ? htmlspecialchars($customer['city']) : '';
$state = isset($customer['state']) ? htmlspecialchars($customer['state']) : '';
$country = isset($customer['country']) ? htmlspecialchars($customer['country']) : '';
$cot = isset($customer['cot']) ? htmlspecialchars($customer['cot']) : '';
$imf = isset($customer['imf']) ? htmlspecialchars($customer['imf']) : '';
$activationcode = isset($customer['activationcode']) ? htmlspecialchars($customer['activationcode']) : '';
$taxcode = isset($customer['taxcode']) ? htmlspecialchars($customer['taxcode']) : '';
$accopendate = isset($customer['accopendate']) ? htmlspecialchars($customer['accopendate']) : '';
$otp = isset($customer['otp']) ? htmlspecialchars($customer['otp']) : '';
$lastlogin = isset($customer['lastlogin']) ? htmlspecialchars($customer['lastlogin']) : '';
$email = isset($customer['email']) ? htmlspecialchars($customer['email']) : '';
$accpassword = isset($customer['accpassword']) ? htmlspecialchars($customer['accpassword']) : '';

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Customer's Details</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="assets/images/favicon.ico">

    <link rel="preconnect" href="https://fonts.googleapis.com/">
    <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&amp;family=Poppins:wght@400;500;700&amp;display=swap">

    <link rel="stylesheet" type="text/css" href="assets/vendor/font-awesome/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/bootstrap-icons/bootstrap-icons.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/overlay-scrollbar/css/overlayscrollbars.min.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/apexcharts/css/apexcharts.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">

    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
</head>
<body>

<main>
    <?php include "include/sidebar.php" ?>
    <div class="page-content">
        <?php include "include/topbar.php" ?>
        <div class="page-content-wrapper p-xxl-4">

            <div class="row">
                <div class="col-12 mb-4 mb-sm-5">
                    <div class="d-sm-flex justify-content-between align-items-center">
                        <h1 class="h3 mb-2 mb-sm-0">Customer's Details</h1>
                    </div>
                </div>
            </div>

            <div class="card shadow">
                <div class="card-header border-bottom">
                    <h5 class="card-title mb-0">Customer Details & Accounts</h5>
                </div>

                <div class="card-body">
                    <?php if (isset($_SESSION['message'])):
                        $message = $_SESSION['message'];
                        unset($_SESSION['message']);
                    ?>
                        <script>
                            document.addEventListener('DOMContentLoaded', function() {
                                Swal.fire({
                                    title: '<?= $message['type'] === 'success' ? 'Successful!' : 'Error!'; ?>',
                                    text: '<?= $message['text']; ?>',
                                    icon: '<?= $message['type']; ?>',
                                    confirmButtonText: 'OK'
                                });
                            });
                        </script>
                    <?php endif; ?>

                    <div class="bg-light rounded p-3 mb-4">
                        <div class="row g-4">
                            <div class="col-lg-6"><h6>Customer Name</h6></div>
                            <div class="col-lg-6"><h6><?= $custname; ?></h6></div>
                            <div class="col-lg-6"><h6>Branch</h6></div>
                            <div class="col-lg-6"><h6><?= $ifsccode; ?></h6></div>
                            <div class="col-lg-6"><h6>Login ID</h6></div>
                            <div class="col-lg-6"><h6><?= $loginid; ?></h6></div>
                            <div class="col-lg-6"><h6>Account Status</h6></div>
                            <div class="col-lg-6"><h6><?= $accstatus; ?></h6></div>
                            <div class="col-lg-6"><h6>City</h6></div>
                            <div class="col-lg-6"><h6><?= $city; ?></h6></div>
                            <div class="col-lg-6"><h6>State</h6></div>
                            <div class="col-lg-6"><h6><?= $state; ?></h6></div>
                            <div class="col-lg-6"><h6>Country</h6></div>
                            <div class="col-lg-6"><h6><?= $country; ?></h6></div>
                            <div class="col-lg-6"><h6>COT</h6></div>
                            <div class="col-lg-6"><h6><?= $cot; ?></h6></div>
                            <div class="col-lg-6"><h6>IMF Code</h6></div>
                            <div class="col-lg-6"><h6><?= $imf; ?></h6></div>
                            <div class="col-lg-6"><h6>Activation Code</h6></div>
                            <div class="col-lg-6"><h6><?= $activationcode; ?></h6></div>
                            <div class="col-lg-6"><h6>Tax Code</h6></div>
                            <div class="col-lg-6"><h6><?= $taxcode; ?></h6></div>
                            
							<div class="col-lg-6"><h6>Login Email</h6></div>
                            <div class="col-lg-6"><h6><?= $email; ?></h6></div>
							
							<div class="col-lg-6"><h6>Login Password</h6></div>
                            <div class="col-lg-6"><h6><?= $accpassword; ?></h6></div>
							
							<div class="col-lg-6"><h6>Account PIN</h6></div>
                            <div class="col-lg-6"><h6><?= $otp; ?></h6></div>
                           

						   <div class="col-lg-6"><h6>Account Open Date</h6></div>
                            <div class="col-lg-6"><h6><?= $accopendate; ?></h6></div>
                            <div class="col-lg-6"><h6>Last Login</h6></div>
                            <div class="col-lg-6"><h6><?= $lastlogin; ?></h6></div>
                        </div>
                    </div>

                    <h5 class="card-title mb-3">Customer Accounts</h5>
                    <div class="bg-light rounded p-3 d-none d-lg-block">
                        <div class="row g-4">
                            <div class="col-lg-3"><h6 class="mb-0">Account No</h6></div>
                            <div class="col-lg-2"><h6 class="mb-0">Status</h6></div>
                            <div class="col-lg-2"><h6 class="mb-0">Open Date</h6></div>
                            <div class="col-lg-2"><h6 class="mb-0">Account Type</h6></div>
                            <div class="col-lg-3"><h6 class="mb-0">Balance</h6></div>
                        </div>
                    </div>
                    <?php if (!empty($accounts)): ?>
                        <?php foreach ($accounts as $account): ?>
                            <div class="row g-4 align-items-center border-bottom px-2 py-4">
                                <div class="col-12 col-lg-3">
                                    <h6 class="mb-0 fw-normal">
                                        <span class="d-lg-none">Account No: </span><?= htmlspecialchars($account['accno']); ?>
                                    </h6>
                                </div>
                                <div class="col-12 col-lg-2">
                                    <h6 class="mb-0 fw-normal">
                                        <span class="d-lg-none">Status: </span><?= htmlspecialchars($account['accstatus']); ?>
                                    </h6>
                                </div>
                                <div class="col-12 col-lg-2">
                                    <h6 class="mb-0 fw-normal">
                                        <span class="d-lg-none">Open Date: </span><?= htmlspecialchars($account['accopendate']); ?>
                                    </h6>
                                </div>
                                <div class="col-12 col-lg-2">
                                    <h6 class="mb-0 fw-normal">
                                        <span class="d-lg-none">Account Type: </span><?= htmlspecialchars($account['accounttype']); ?>
                                    </h6>
                                </div>
                                <div class="col-12 col-lg-3">
                                    <h6 class="mb-0 fw-normal">
                                        <span class="d-lg-none">Balance: </span>
<?= htmlspecialchars($cur) . ' ' . number_format((float)$account['accountbalance'], 2); ?>

                                    </h6>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <div class="row px-2 py-4 text-center">
                            <div class="col">
                                <p class="mb-0">No accounts found for this customer.</p>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>

               <div class="card-footer pt-0">
    <div class="d-flex justify-content-start align-items-center mt-3">
        <form method="post" action="">
            <input type="hidden" name="custid" value="<?= $custid ?>">
            <button type="submit" class="btn btn-danger" name="Del" onclick="return confirm('Are you sure you want to delete this customer and all their accounts?');">
                Delete Customer
            </button>
        </form>
        <a href='edit_account.php?custid=<?= $custid ?>' class="btn btn-primary-soft ms-2">
            Edit Account
        </a>
        <form method="post" action="" class="ms-2">
            <input type="hidden" value='<?= $custid ?>' name="hide_id">
            <?php if ($accstatus == 'onreview'): ?>
                <button class="btn btn-success" type="submit" name="approve_customer">
                    Approve Account
                </button>
            <?php elseif ($accstatus == 'active'): ?>
                <button class="btn btn-warning" type="submit" name="blockcustomer">
                    Block Account
                </button>
            <?php elseif ($accstatus == 'blocked'): ?>
                <button class="btn btn-success" type="submit" name="unblockcustomer">
                    Unblock Account
                </button>
            <?php endif; ?>
        </form>
    </div>
</div>
            </div>
        </div>
    </div>
</main>

<script src="assets/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/overlay-scrollbar/js/overlayscrollbars.min.js"></script>
<script src="assets/vendor/apexcharts/js/apexcharts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.all.min.js"></script>
<script src="assets/js/functions.js"></script>
</body>
</html>