<?php
// session_start();
require("../includes/db_connect.php");
require_once("includes/session_token.php");

$accountId = $_SESSION['usr_accountId'];

$balance_sql = "SELECT * FROM wallet WHERE accountId=? LIMIT 1";
$balance_sth = $conn->prepare($balance_sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$balance_sth->execute([$accountId]);
$account_balances = $balance_sth->fetchAll();

foreach ($account_balances as $key => $value) {
    $usr_balance = $value['balance'];
    $usr_withdrawn = $value['withdrawn'];

    $balance = number_format($usr_balance, 2);
    $withdrawn = number_format($usr_withdrawn, 2);
}

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Wallet</title>
    <link rel="stylesheet" href="../css/bootstrap-select-country.min.css" />
    <link rel="stylesheet" href="../build/css/intlTelInput.css">

    <?php require_once("includes/header.php"); ?>


    <div class="content ht-100v pd-0">
        <div class="content-header center">
            <img src="../img/logo-white.png" class="aside-logo" style="width: 160px;" />
        </div>
        <div class="content-body">
            <div class="container pd-x-0">
                <div class="d-sm-flex align-items-center justify-content-between mg-b-20 mg-lg-b-25 mg-xl-b-30">
                    <div>
                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb breadcrumb-style1 mg-b-10">
                                <li class="breadcrumb-item"><a href="account">Dashboard</a></li>
                            </ol>
                        </nav>
                        <h4 class="mg-b-0 tx-spacing--1">Wallet</h4>
                    </div>
                </div>

                <div class="row row-xs">
                    <div class="col-md-3 col-lg-3 col-sm-12">
                        <div class="card">
                            <div class="card-body">
                                <nav class="nav nav-classic tx-13">
                                    <a id="mmn-profile-settings" href="profile-settings" class="nav-link"><i
                                            data-feather="user"></i> <span>Profile</span></a>
                                    <a id="mmn-profile-wallet" href="profile-wallet" style="margin-top: 25px;" class="nav-link"><i
                                            data-feather="credit-card"></i> <span>Wallet</span></a>
                                    <a id="mmn-change-password" href="change-password" class="nav-link"><i
                                            data-feather="lock" style="height: 50px;"></i> <span>Change
                                            Password</span></a>
                                    <a id="mmn-delete-account" href="delete-account" class="nav-link"><i
                                            data-feather="archive"></i> <span>Delete Account</span></a>

                                </nav>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-9 col-lg-9 col-sm-12">
                        <div class="row">
                            <div class="col-sm-6 col-lg-6">
                                <div class="card card-body">
                                    <h6 class="tx-uppercase tx-11 tx-spacing-1 tx-color-02 tx-semibold mg-b-8">Balance
                                    </h6>
                                    <div class="d-flex d-lg-block d-xl-flex align-items-end">
                                        <h3 class="tx-normal tx-rubik mg-b-0 mg-r-5 lh-1">$<?php echo ($balance); ?>
                                        </h3>
                                    </div>
                                </div>
                            </div><!-- col -->
                            <div class="col-sm-6 col-lg-6 mg-t-10 mg-sm-t-0">
                                <div class="card card-body">
                                    <h6 class="tx-uppercase tx-11 tx-spacing-1 tx-color-02 tx-semibold mg-b-8">Withdrawn
                                    </h6>
                                    <div class="d-flex d-lg-block d-xl-flex align-items-end">
                                        <h3 class="tx-normal tx-rubik mg-b-0 mg-r-5 lh-1">
                                            $<?php echo ($withdrawn); ?></h3>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="d-md-block" style="margin-top: 30px; margin-bottom: 30px">
                            <a href="deposit" class="btn btn-sm pd-x-15 btn-white btn-uppercase mg-l-5"><i
                                    data-feather="bar-chart" class="wd-10 mg-r-5"></i> Deposit</a>
                            <a href="transfer-funds"
                                class="btn btn-sm pd-x-15 btn-white btn-uppercase mg-l-5"><i data-feather="dollar-sign"
                                    class="wd-10 mg-r-5"></i> Transfer Funds</a>
                        </div>
                    </div>
                </div>

            </div>
        </div><!-- content-body -->
    </div><!-- content -->

    <?php require_once("includes/footer.php"); ?>
    <script src="../build/js/intlTelInput.min.js"></script>
    <script src="../build/js/intlTelInput-jquery.min.js"></script>
    <script src="../js/bootstrap-select-country.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        var classes = $("#mn-settings").prop('class');
        $("#mn-settings").prop('class', classes + ' active pcoded-trigger');

        var classes = $("#mmn-profile-wallet").prop('class');
        $("#mmn-profile-wallet").prop('class', classes + ' active pcoded-trigger');

    });
    </script>

    </body>

</html>