<?php
session_start();
if (!isset($_SESSION['chap'])) {
    header("Location: ../index.html#login-area");
    exit();
} else {
    $chap = $_SESSION['chap'];
    include "../connect/db.php";
    $sql = mysqli_query($mysqli, "SELECT * FROM users WHERE email = '$chap'");
    $row = mysqli_fetch_assoc($sql);
    if ($row['status'] == "suspended") { header("Location: account.php"); exit(); }
    else if ($row['status'] == "terminated") { header("Location: terminate.php"); exit(); }

    if ($row['kyc_status'] == "pending" || $row['kyc_status'] == "review") {
        header("Location: kyc.php"); exit();
    }
    if ($row['code_level'] != "nothing" && $row['lock_status'] == "active") {
        header("Location: auth.php"); exit();
    }
}
?>
<!DOCTYPE html>
<html lang="en-US" class="js">
<head>
    <?php $pageTitle = $row['firstname'] . ' ' . $row['lastname'] . ' — Profile'; ?>
    <?php include 'includes/head.php'; ?>
    <link rel="stylesheet" href="https://www.jqueryscript.net/demo/jQuery-International-Telephone-Input-With-Flags-Dial-Codes/build/css/intlTelInput.css">
</head>
<body class="nk-body npc-crypto bg-white has-sidebar">
    <div class="nk-app-root">
        <div class="nk-main">
            <div class="nk-sidebar nk-sidebar-fixed" data-content="sidebarMenu">
                <div class="nk-sidebar-element nk-sidebar-head">
                    <div class="nk-sidebar-brand">
                        <a href="dashboard" class="logo-link nk-sidebar-logo">
                            <img class="logo-light logo-img" src="../logo.png" srcset="../logo.png 2x" alt="logo">
                            <img class="logo-dark logo-img" src="../logo.png" srcset="../logo.png 2x" alt="logo-dark">
                        </a>
                    </div>
                    <div class="nk-menu-trigger mr-n2">
                        <a href="#" class="nk-nav-toggle nk-quick-nav-icon d-xl-none" data-target="sidebarMenu"><em class="icon ni ni-arrow-left"></em></a>
                    </div>
                </div>
              <?php include 'includes/sidebar.php'; ?>

          <div class="nk-content nk-content-fluid">
            <div class="container-xl wide-lg">
              <div class="nk-content-body">

                <div class="nk-block-head">
                  <div class="nk-block-head-content">
                    <h2 class="nk-block-title fw-normal">My Profile</h2>
                    <div class="nk-block-des"><p>Your personal and account information.</p></div>
                  </div>
                </div>

                <!-- Personal Information -->
                <div class="nk-block">
                  <div class="nk-block-head">
                    <h5 class="nk-block-title">Personal Information</h5>
                  </div>
                  <div class="nk-data data-list">
                    <div class="data-head"><h6 class="overline-title">Name &amp; Identity</h6></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Title</span><span class="data-value"><?=$row['title']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Full Name</span><span class="data-value"><?=$row['firstname']?> <?=$row['middlename']?> <?=$row['lastname']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">First Name</span><span class="data-value"><?=$row['firstname']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Middle Name</span><span class="data-value"><?=$row['middlename'] ?: '—'?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Last Name</span><span class="data-value"><?=$row['lastname']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Gender</span><span class="data-value"><?=ucfirst($row['gender'])?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Date of Birth</span><span class="data-value"><?=$row['dob']?></span></div></div>
                  </div>
                  <div class="nk-data data-list mt-3">
                    <div class="data-head"><h6 class="overline-title">Contact</h6></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Email</span><span class="data-value"><?=$row['email']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Phone</span><span class="data-value"><?=$row['phone']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Address</span><span class="data-value"><?=$row['address'] ?: '—'?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Country</span><span class="data-value"><?=$row['country']?></span></div></div>
                  </div>
                </div>

                <!-- Account Information -->
                <div class="nk-block">
                  <div class="nk-block-head">
                    <h5 class="nk-block-title">Account Information</h5>
                  </div>
                  <div class="nk-data data-list">
                    <div class="data-head"><h6 class="overline-title">Account Details</h6></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Account Number</span><span class="data-value font-monospace"><?=maskNumber($row['account_num'], 5)?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Account Type</span><span class="data-value"><?=$row['account_type']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Account Currency</span><span class="data-value"><?=currencySymbol($row['usercurrency'])?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Checking Balance</span><span class="data-value fw-bold"><?=formatCurrency($row['checking_balance'], $row['usercurrency'])?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">BSL Balance</span><span class="data-value"><?=formatCurrency($row['bsl_balance'], $row['usercurrency'])?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Linked Cards</span><span class="data-value"><?=$row['linked_card']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">FICO Score</span><span class="data-value"><?=$row['fico_score']?></span></div></div>
                  </div>
                  <div class="nk-data data-list mt-3">
                    <div class="data-head"><h6 class="overline-title">Account Status</h6></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Account Status</span><span class="data-value"><span class="badge badge-<?=$row['status']=='active'?'success':'warning'?>"><?=ucfirst($row['status'])?></span></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">KYC Status</span><span class="data-value"><span class="badge badge-<?=$row['kyc_status']=='approved'?'success':'warning'?>"><?=ucfirst($row['kyc_status'])?></span></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Registration Step</span><span class="data-value"><?=$row['reg_step']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Security Level</span><span class="data-value"><?=$row['code_level']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Account Lock</span><span class="data-value"><?=$row['lock_status']?></span></div></div>
                  </div>
                </div>

                <!-- Security -->
                <div class="nk-block">
                  <div class="nk-block-head">
                    <h5 class="nk-block-title">Security</h5>
                  </div>
                  <div class="nk-data data-list">
                    <div class="data-item"><div class="data-col"><span class="data-label">Security Question</span><span class="data-value"><?=$row['securityquestion']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Security Answer</span><span class="data-value"><?=$row['answer']?></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Password</span><span class="data-value">••••••••</span><span class="data-more"><a href="password-reset" class="btn btn-xs btn-outline-primary">Change</a></span></div></div>
                    <div class="data-item"><div class="data-col"><span class="data-label">Login Activity</span><span class="data-value"><a href="activity-logs" class="link link-primary">View Activity Log</a></span></div></div>
                  </div>
                </div>

              </div>
            </div>
          </div>

    <?php include 'includes/footer.php'; ?>
