<?php
require '../../config/db.php';
ini_set("display_errors", 0);
require 'security_admin.php';
require 'adminInfos.php';
include 'updatePlatformAdmin.php';

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

$idUser = filter_input(INPUT_POST, 'id_user', FILTER_SANITIZE_NUMBER_INT);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['edit_user'])) {
        $stmtUser = $pdo->prepare("SELECT * FROM users WHERE id = :id");
        $stmtUser->execute([':id' => $idUser]);

        if ($stmtUser->rowCount() === 0) {
            echo json_encode(['error' => 'Usuário NOT FOUND 404.']);
            exit;
        }

        $resultUser = $stmtUser->fetch(PDO::FETCH_ASSOC);

        $stmt = $pdo->prepare("SELECT * FROM transactions WHERE user_id = :user_id");
        $stmt->execute([':user_id' => $resultUser['id']]);
        $userTransactions = $stmt->fetchAll(PDO::FETCH_ASSOC);

        $stmt2 = $pdo->prepare("SELECT * FROM withdrawal WHERE user_id = :user_id");
        $stmt2->execute([':user_id' => $resultUser['id']]);
        $userWithdrawals = $stmt2->fetchAll(PDO::FETCH_ASSOC);

        $stmt3 = $pdo->prepare("SELECT * FROM investments WHERE user_id = :user_id");
        $stmt3->execute([':user_id' => $resultUser['id']]);
        $userInvestments = $stmt3->fetchAll(PDO::FETCH_ASSOC);
    } elseif (isset($_POST['save-user'])) {
        $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_FULL_SPECIAL_CHARS);

        try {
            $stmtUser = $pdo->prepare("SELECT * FROM users WHERE id = :id");
            $stmtUser->execute([':id' => $idUser]);

            if ($stmtUser->rowCount() === 0) {
                echo json_encode(['error' => 'User NOT FOUND 404.']);
                exit;
            }

            $pdo->beginTransaction();
            $stmtUserUpdate = $pdo->prepare("UPDATE users SET phone = :phone, status = :status, balance = :balance, lider = :lider WHERE id = :id");
            $stmtUserUpdate->execute([
                ':phone' => $data['phone'],
                ':status' => $data['status'],
                ':balance' => $data['balance'],
                ':lider' => $data['lider'],
                ':id' => $idUser,
            ]);
            $pdo->commit();
            $_SESSION['toast_message'] = 'Usuário atualizado com sucesso!';
            $_SESSION['toast_type'] = 'success';
            header('Location: ../../public/dash/administer_users.php');
            exit;
        } catch (PDOException $e) {
            $pdo->rollBack();
            $_SESSION['toast_message'] = 'Ocorreu um erro ao atualizar o usuário: ' . $e->getMessage();
            $_SESSION['toast_type'] = 'error';
        }
    } elseif (isset($_POST['edit-pass-user'])) {
        $pass = filter_input(INPUT_POST, 'password');

        $stmtUser = $pdo->prepare("SELECT * FROM users WHERE id = :id");
        $stmtUser->execute([':id' => $idUser]);

        if ($stmtUser->rowCount() === 0) {
            echo json_encode(['error' => 'Usuário NOT FOUND 404.']);
            exit;
        }

        $resultUser = $stmtUser->fetch(PDO::FETCH_ASSOC);

        try {
            $pdo->beginTransaction();

            $stmtUpdatePass = $pdo->prepare("UPDATE users SET password = :password WHERE id = :id");
            $stmtUpdatePass->execute([
                ':password' => password_hash($pass, PASSWORD_DEFAULT),
                ':id' => $resultUser['id']
            ]);

            $pdo->commit();
            $_SESSION['toast_message'] = 'Senha alterada com sucesso!';
            $_SESSION['toast_type'] = 'success';
            header('Location: ../../public/dash/administer_users.php');
            exit;
        } catch (PDOException $e) {
            $pdo->rollBack();
            $_SESSION['toast_message'] = 'Ocorreu um erro ao atualizar a senha do usuário: ' . $e->getMessage();
            $_SESSION['toast_type'] = 'error';
            header('Location: ../../public/dash/administer_users.php');
            exit;
        }
    }
}
?>

<?php if ($resultUser) : ?>
    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="apple-touch-icon" sizes="76x76" href="../../public/dash/assets/img/apple-icon.png">
        <link rel="icon" type="image/png" href="../../public/dash/assets/img/favicon.png">
        <title>
            Black Dashboard by Creative Tim
        </title>
        <!--     Fonts and icons     -->
        <link href="https://fonts.googleapis.com/css?family=Poppins:200,300,400,600,700,800" rel="stylesheet" />
        <link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
        <!-- Nucleo Icons -->
        <link href="../../public/dash/assets/css/nucleo-icons.css" rel="stylesheet" />
        <link rel="stylesheet" href="../../public/dash/assets/css/build/tailwind.css" />
        <!-- CSS Files -->
        <link href="../../public/dash/assets/css/black-dashboard.css?v=1.0.0" rel="stylesheet" />
        <!-- CSS Just for demo purpose, don't include it in your project -->
        <link href="../../public/dash/assets/demo/demo.css" rel="stylesheet" />
    </head>

    <body class="">

        <?php if ($toastMessage) : ?>
            <?php if ($toastType === 'success') : ?>
                <div
                    id="toast"
                    class="fixed bottom-4 right-4 z-50 bg-green-600 text-white px-4 py-3 rounded-lg shadow-lg animate-slide-in flex items-center gap-2 w-[90%] max-w-sm">
                    <svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
                    </svg>
                    <span><?= htmlspecialchars($toastMessage) ?></span>
                </div>
            <?php elseif ($toastType === 'error') : ?>
                <div style="background-color: red;"
                    id="toast"
                    class="fixed bottom-4 right-4 z-50 bg-red-600 text-white px-4 py-3 rounded-lg shadow-lg animate-slide-in flex items-center gap-2 w-[90%] max-w-sm">
                    <svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                    <span><?= htmlspecialchars($toastMessage) ?></span>
                </div>
            <?php endif; ?>
        <?php endif; ?>

        <div class="wrapper">
            <div class="sidebar">
                <!--
        Tip 1: You can change the color of the sidebar using: data-color="blue | green | orange | red"
    -->
                <div class="sidebar-wrapper">
                    <div class="logo">
                        <a href="javascript:void(0)" class="simple-text logo-mini">
                            CT
                        </a>
                        <a href="javascript:void(0)" class="simple-text logo-normal">
                            Creative Tim
                        </a>
                    </div>
                    <ul class="nav">
                        <li>
                            <a href="../../public/dash/index.php">
                                <i class="tim-icons icon-chart-pie-36"></i>
                                <p>Dashboard</p>
                            </a>
                        </li>
                        <li>
                            <a href="../../public/dash/configs.php">
                                <i class="tim-icons icon-atom"></i>
                                <p>Configurações Gerais</p>
                            </a>
                        </li>
                        <li>
                            <a href="../../public/dash/administer_users.php">
                                <i class="tim-icons icon-single-02"></i>
                                <p>Usuários</p>
                            </a>
                        </li>
                        <li class="active">
                            <a href="../../public/dash/administer_products.php">
                                <i class="tim-icons icon-align-center"></i>
                                <p>Produtos</p>
                            </a>
                        </li>
                        <li>
                            <a href="../../public/dash/cashout_pending.php">
                                <i class="tim-icons icon-world"></i>
                                <p>Saques Pendentes <span class="badge badge-warning rounded-sm text-dark"><?= count($resultWithdrawalPending) ?></span></p>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="main-panel">
                <!-- Navbar -->
                <nav class="navbar navbar-expand-lg navbar-absolute navbar-transparent">
                    <div class="container-fluid">
                        <div class="navbar-wrapper">
                            <div class="navbar-toggle d-inline">
                                <button type="button" class="navbar-toggler">
                                    <span class="navbar-toggler-bar bar1"></span>
                                    <span class="navbar-toggler-bar bar2"></span>
                                    <span class="navbar-toggler-bar bar3"></span>
                                </button>
                            </div>
                            <a class="navbar-brand" href="javascript:void(0)">Administrando Usuário</a>
                        </div>
                        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation" aria-expanded="false" aria-label="Toggle navigation">
                            <span class="navbar-toggler-bar navbar-kebab"></span>
                            <span class="navbar-toggler-bar navbar-kebab"></span>
                            <span class="navbar-toggler-bar navbar-kebab"></span>
                        </button>
                        <div class="collapse navbar-collapse" id="navigation">
                            <ul class="navbar-nav ml-auto">
                                <li class="search-bar input-group">
                                    <button class="btn btn-link" id="search-button" data-toggle="modal" data-target="#searchModal"><i class="tim-icons icon-zoom-split"></i>
                                        <span class="d-lg-none d-md-block">Search</span>
                                    </button>
                                </li>
                                <li class="dropdown nav-item">
                                    <a href="javascript:void(0)" class="dropdown-toggle nav-link" data-toggle="dropdown">
                                        <div class="notification d-none d-lg-block d-xl-block"></div>
                                        <i class="tim-icons icon-sound-wave"></i>
                                        <p class="d-lg-none">
                                            Notifications
                                        </p>
                                    </a>
                                    <ul class="dropdown-menu dropdown-menu-right dropdown-navbar">
                                        <li class="nav-link"><a href="#" class="nav-item dropdown-item">Mike John responded to your email</a></li>
                                        <li class="nav-link"><a href="javascript:void(0)" class="nav-item dropdown-item">You have 5 more tasks</a></li>
                                        <li class="nav-link"><a href="javascript:void(0)" class="nav-item dropdown-item">Your friend Michael is in town</a></li>
                                        <li class="nav-link"><a href="javascript:void(0)" class="nav-item dropdown-item">Another notification</a></li>
                                        <li class="nav-link"><a href="javascript:void(0)" class="nav-item dropdown-item">Another one</a></li>
                                    </ul>
                                </li>
                                <li class="dropdown nav-item">
                                    <a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown">
                                        <div class="photo">
                                            <img src="../assets/img/anime3.png" alt="Profile Photo">
                                        </div>
                                        <b class="caret d-none d-lg-block d-xl-block"></b>
                                        <p class="d-lg-none">
                                            Log out
                                        </p>
                                    </a>
                                    <ul class="dropdown-menu dropdown-navbar">
                                        <li class="nav-link"><a href="javascript:void(0)" class="nav-item dropdown-item">Profile</a></li>
                                        <li class="nav-link"><a href="javascript:void(0)" class="nav-item dropdown-item">Settings</a></li>
                                        <li class="dropdown-divider"></li>
                                        <li class="nav-link"><a href="javascript:void(0)" class="nav-item dropdown-item">Log out</a></li>
                                    </ul>
                                </li>
                                <li class="separator d-lg-none"></li>
                            </ul>
                        </div>
                    </div>
                </nav>
                <div class="modal modal-search fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="searchModal" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <input type="text" class="form-control" id="inlineFormInputGroup" placeholder="SEARCH">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <i class="tim-icons icon-simple-remove"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- End Navbar -->
                <div class="content">
                    <div class="row">
                        <div class="col-md-8">
                            <div class="card shadow-sm border-0">
                                <div class="card-header bg-[#005E60] text-white">
                                    <h5 class="mb-3">Editando usuário <strong><?= htmlspecialchars($resultUser['phone']) ?></strong></h5>
                                </div>

                                <form method="POST" class="p-4">
                                    <div class="row g-4">
                                        <div class="col-md-4">
                                            <label for="id_user" class="form-label fw-semibold">ID do Usuário</label>
                                            <input type="text" id="id_user" name="id_user" class="form-control" value="<?= htmlspecialchars($resultUser['id']) ?>" readonly>
                                        </div>

                                        <div class="col-md-4">
                                            <label for="phone" class="form-label fw-semibold">Telefone</label>
                                            <input type="text" id="phone" name="phone" class="form-control" value="<?= htmlspecialchars($resultUser['phone']) ?>" placeholder="(00) 00000-0000">
                                        </div>

                                        <div class="col-md-4">
                                            <label for="status" class="form-label fw-semibold">Status da Conta</label>
                                            <select id="status" name="status" class="form-control">
                                                <option value="active" <?= $resultUser['status'] === 'active' ? 'selected' : '' ?>>Ativo</option>
                                                <option value="banned" <?= $resultUser['status'] === 'banned' ? 'selected' : '' ?>>Banido</option>
                                            </select>
                                        </div>

                                         <div class="col-md-4">
                                            <label for="lider" class="form-label fw-semibold">Lider ?</label>
                                            <select id="lider" name="lider" class="form-control">
                                                <option value="yes" <?= $resultUser['lider'] === 'yes' ? 'selected' : '' ?>>Sim</option>
                                                <option value="no" <?= $resultUser['lider'] === 'no' ? 'selected' : '' ?>>Não</option>
                                            </select>
                                        </div>

                                        <div class="col-md-4">
                                            <label for="balance" class="form-label fw-semibold">Saldo Atual (R$)</label>
                                            <input type="text" id="balance" name="balance" class="form-control" value="<?= htmlspecialchars($resultUser['balance']) ?>" placeholder="0.00">
                                        </div>

                                        <div class="col-md-6">
                                            <label for="client_ip" class="form-label fw-semibold">IP de Cadastro</label>
                                            <input type="text" id="client_ip" name="client_ip" class="form-control" value="<?= htmlspecialchars($resultUser['client_ip']) ?>" readonly>
                                        </div>

                                        <div class="col-md-6">
                                            <label for="date" class="form-label fw-semibold">Data Cadastro</label>
                                            <input type="text" id="date" name="date" class="form-control" value="<?= htmlspecialchars($resultUser['date']) ?>" readonly>
                                        </div>

                                        <div class="col-md-6">
                                            <label for="last_login" class="form-label fw-semibold">Último Login</label>
                                            <input type="text" id="last_login" name="last_login" class="form-control" value="<?= htmlspecialchars($resultUser['last_login']) ?>" readonly>
                                        </div>

                                        <div class="col-md-6">
                                            <label for="qtd_investments" class="form-label fw-semibold">Total Investimentos</label>
                                            <input type="text" id="qtd_investments" name="qtd_investments" class="form-control" value="<?= htmlspecialchars($resultUser['qtd_investments']) ?>" readonly>
                                        </div>

                                        <br>
                                        <h4 style="margin-top: 20px;" class="ml-4 mt-6">ÁREA AFILIADO</h4>

                                        <div class="col-md-6">
                                            <label for="affiliate_code" class="form-label fw-semibold">Código de Afiliado</label>
                                            <input type="text" id="affiliate_code" name="affiliate_code" class="form-control" value="<?= htmlspecialchars($resultUser['affiliate_code']) ?>" readonly>
                                        </div>

                                        <div class="col-md-4">
                                            <label for="indicated_by" class="form-label fw-semibold">Indicado por</label>
                                            <input type="text" id="indicated_by" name="indicated_by" class="form-control" value="<?= htmlspecialchars(($resultUser['indicated_by'])) == null ? 'SEM INDICAÇÃO' : htmlspecialchars($resultUser['indicated_by']) ?>" placeholder="Código do afiliado que indicou" readonly>
                                        </div>

                                        <div class="col-md-4">
                                            <label for="total_lvl1" class="form-label fw-semibold">Total Nível A</label>
                                            <input type="text" id="total_lvl1" name="total_lvl1" class="form-control" value="<?= htmlspecialchars($resultUser['total_lvl1']) ?>" readonly>
                                        </div>

                                        <div class="col-md-4">
                                            <label for="total_lvl2" class="form-label fw-semibold">Total Nível B</label>
                                            <input type="text" id="total_lvl2" name="total_lvl2" class="form-control" value="<?= htmlspecialchars($resultUser['total_lvl2']) ?>" readonly>
                                        </div>

                                        <div class="col-md-4">
                                            <label for="total_lvl3" class="form-label fw-semibold">Total Nível C</label>
                                            <input type="text" id="total_lvl3" name="total_lvl3" class="form-control" value="<?= htmlspecialchars($resultUser['total_lvl3']) ?>" readonly>
                                        </div>

                                        <div class="col-md-4">
                                            <label for="total_indicated_deposits" class="form-label fw-semibold">Total Depósitos Indicados</label>
                                            <input type="text" id="total_indicated_deposits" name="total_indicated_deposits" class="form-control" value="<?= htmlspecialchars($resultUser['total_indicated_deposits']) ?>" readonly>
                                        </div>
                                    </div>

                                    <div class="mt-4 text-end">
                                        <button name="save-user" type="submit" class="btn btn-success px-4">
                                            <i class="bx bx-save me-1"></i> Salvar Dados do Usuário
                                        </button>
                                    </div>
                                </form>

                            </div>
                        </div>

                        <div class="content">
                            <div class="row">
                                <div class="col-md-8">
                                    <div class="card shadow-sm border-0">
                                        <div class="card-header bg-[#005E60] text-white">
                                            <h5 class="mb-3">ALTERAÇÃO DE SENHA</h5>
                                        </div>

                                        <form method="POST" class="p-4">
                                            <div class="row g-4">
                                                <div class="col-md-4">
                                                    <label for="id_user" class="form-label fw-semibold">ID do Usuário</label>
                                                    <input type="text" id="id_user" name="id_user" class="form-control" value="<?= htmlspecialchars($resultUser['id']) ?>" readonly>
                                                </div>

                                                <div class="col-md-4">
                                                    <label for="password" class="form-label fw-semibold">Nova senha do usuário</label>
                                                    <input type="text" id="password" name="password" class="form-control" placeholder="Insira a nova senha">
                                                </div>

                                                <div class="mt-4 ml-3 text-end">
                                                    <button name="edit-pass-user" type="submit" class="btn btn-success px-4">
                                                        <i class="bx bx-save me-1"></i> Alterar Senha
                                                    </button>
                                                </div>
                                        </form>

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


                                    <div class="col-md-4">
                                        <div class="card card-user">
                                            <div class="card-body">
                                                <h5 class="title">Investimentos</h5>
                                                <div class="card-description">
                                                    <table class="table">
                                                        <thead>
                                                            <tr>
                                                                <th>Nome</th>
                                                                <th>Investido</th>
                                                                <th>Retorno</th>
                                                                <th>Duração</th>
                                                                <th>Ativo</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php foreach ($userInvestments as $inv): ?>
                                                                <tr>
                                                                    <td><?= htmlspecialchars($inv['name']) ?></td>
                                                                    <td>R$ <?= htmlspecialchars($inv['invested_amount']) ?></td>
                                                                    <td>R$ <?= htmlspecialchars($inv['total_return']) ?></td>
                                                                    <td><?= htmlspecialchars($inv['duration_days']) ?> dias</td>
                                                                    <td><?= $inv['is_active'] ? 'Sim' : 'Não' ?></td>
                                                                </tr>
                                                            <?php endforeach; ?>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-md-4">
                                        <div class="card card-user">
                                            <div class="card-body">
                                                <h5 class="title">Transações</h5>
                                                <div class="card-description">
                                                    <table class="table">
                                                        <thead>
                                                            <tr>
                                                                <th>Valor</th>
                                                                <th>Status</th>
                                                                <th>Criada em</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php foreach ($userTransactions as $tx): ?>
                                                                <tr>
                                                                    <td>R$ <?= htmlspecialchars($tx['value']) ?></td>
                                                                    <td><?= htmlspecialchars($tx['status']) ?></td>
                                                                    <td><?= htmlspecialchars($tx['created_at']) ?></td>
                                                                </tr>
                                                            <?php endforeach; ?>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-md-4">
                                        <div class="card card-user">
                                            <div class="card-body">
                                                <h5 class="title">Saques</h5>
                                                <div class="card-description">
                                                    <?php if (count($userWithdrawals) === 0): ?>
                                                        <p>Nenhum saque encontrado.</p>
                                                    <?php else: ?>
                                                        <table class="table">
                                                            <thead>
                                                                <tr>
                                                                    <th>ID</th>
                                                                    <th>Valor</th>
                                                                    <th>Status</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php foreach ($userWithdrawals as $w): ?>
                                                                    <tr>
                                                                        <td><?= htmlspecialchars($w['id']) ?></td>
                                                                        <td>R$ <?= htmlspecialchars($w['value']) ?></td>
                                                                        <td><?= htmlspecialchars($w['status']) ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </div>


                                        <footer class="footer">
                                            <div class="container-fluid">
                                                <div class="copyright">
                                                    ©
                                                    <script>
                                                        document.write(new Date().getFullYear())
                                                    </script> made with <i class="tim-icons icon-heart-2"></i> by
                                                    <a href="https://wa.me/48991342051" target="_blank">TRYBE IGAMING</a>.
                                                </div>
                                            </div>
                                        </footer>
                                    </div>
                                </div>
                                <div class="fixed-plugin">
                                    <div class="dropdown show-dropdown">
                                        <a href="#" data-toggle="dropdown">
                                            <i class="fa fa-cog fa-2x"> </i>
                                        </a>
                                        <ul class="dropdown-menu">
                                            <li class="header-title"> Sidebar Background</li>
                                            <li class="adjustments-line">
                                                <a href="javascript:void(0)" class="switch-trigger background-color">
                                                    <div class="badge-colors text-center">
                                                        <span class="badge filter badge-[#005E60] active" data-color="primary"></span>
                                                        <span class="badge filter badge-info" data-color="blue"></span>
                                                        <span class="badge filter badge-success" data-color="green"></span>
                                                    </div>
                                                    <div class="clearfix"></div>
                                                </a>
                                            </li>
                                            <li class="adjustments-line text-center color-change">
                                                <span class="color-label">LIGHT MODE</span>
                                                <span class="badge light-badge mr-2"></span>
                                                <span class="badge dark-badge ml-2"></span>
                                                <span class="color-label">DARK MODE</span>
                                            </li>
                                            <li class="button-container">
                                                <a href="https://www.creative-tim.com/product/black-dashboard" target="_blank" class="btn btn-[#005E60] btn-block btn-round">Download Now</a>
                                                <a href="https://demos.creative-tim.com/black-dashboard/docs/1.0/getting-started/introduction.html" target="_blank" class="btn btn-default btn-block btn-round">
                                                    Documentation
                                                </a>
                                            </li>
                                            <li class="header-title">Thank you for 95 shares!</li>
                                            <li class="button-container text-center">
                                                <button id="twitter" class="btn btn-round btn-info"><i class="fab fa-twitter"></i> &middot; 45</button>
                                                <button id="facebook" class="btn btn-round btn-info"><i class="fab fa-facebook-f"></i> &middot; 50</button>
                                                <br>
                                                <br>
                                                <a class="github-button" href="https://github.com/creativetimofficial/black-dashboard" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star ntkme/github-buttons on GitHub">Star</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                                <!--   Core JS Files   -->
                                <script src="assets/js/core/jquery.min.js"></script>
                                <script src="assets/js/core/popper.min.js"></script>
                                <script src="assets/js/core/bootstrap.min.js"></script>
                                <script src="assets/js/plugins/perfect-scrollbar.jquery.min.js"></script>
                                <!--  Google Maps Plugin    -->
                                <!-- Place this tag in your head or just before your close body tag. -->
                                <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_HERE"></script>
                                <!-- Chart JS -->
                                <script src="assets/js/plugins/chartjs.min.js"></script>
                                <!--  Notifications Plugin    -->
                                <script src="assets/js/plugins/bootstrap-notify.js"></script>
                                <!-- Control Center for Black Dashboard: parallax effects, scripts for the example pages etc -->
                                <script src="assets/js/black-dashboard.min.js?v=1.0.0"></script><!-- Black Dashboard DEMO methods, don't include it in your project! -->
                                <script src="assets/demo/demo.js"></script>
                                <script>
                                    const toast = document.getElementById("toast");

                                    if (toast) {
                                        toast.classList.add("opacity-0");
                                        toast.style.transition = "opacity 0.4s ease";

                                        setTimeout(() => {
                                            toast.classList.remove("opacity-0");
                                            toast.classList.add("opacity-100");
                                        }, 100);

                                        setTimeout(() => {
                                            toast.classList.add("opacity-0");
                                            setTimeout(() => toast.remove(), 400);
                                        }, 5000);
                                    }

                                    $(document).ready(function() {
                                        $().ready(function() {
                                            $sidebar = $('.sidebar');
                                            $navbar = $('.navbar');
                                            $main_panel = $('.main-panel');

                                            $full_page = $('.full-page');

                                            $sidebar_responsive = $('body > .navbar-collapse');
                                            sidebar_mini_active = true;
                                            white_color = false;

                                            window_width = $(window).width();

                                            fixed_plugin_open = $('.sidebar .sidebar-wrapper .nav li.active a p').html();



                                            $('.fixed-plugin a').click(function(event) {
                                                if ($(this).hasClass('switch-trigger')) {
                                                    if (event.stopPropagation) {
                                                        event.stopPropagation();
                                                    } else if (window.event) {
                                                        window.event.cancelBubble = true;
                                                    }
                                                }
                                            });

                                            $('.fixed-plugin .background-color span').click(function() {
                                                $(this).siblings().removeClass('active');
                                                $(this).addClass('active');

                                                var new_color = $(this).data('color');

                                                if ($sidebar.length != 0) {
                                                    $sidebar.attr('data', new_color);
                                                }

                                                if ($main_panel.length != 0) {
                                                    $main_panel.attr('data', new_color);
                                                }

                                                if ($full_page.length != 0) {
                                                    $full_page.attr('filter-color', new_color);
                                                }

                                                if ($sidebar_responsive.length != 0) {
                                                    $sidebar_responsive.attr('data', new_color);
                                                }
                                            });

                                            $('.switch-sidebar-mini input').on("switchChange.bootstrapSwitch", function() {
                                                var $btn = $(this);

                                                if (sidebar_mini_active == true) {
                                                    $('body').removeClass('sidebar-mini');
                                                    sidebar_mini_active = false;
                                                    blackDashboard.showSidebarMessage('Sidebar mini deactivated...');
                                                } else {
                                                    $('body').addClass('sidebar-mini');
                                                    sidebar_mini_active = true;
                                                    blackDashboard.showSidebarMessage('Sidebar mini activated...');
                                                }

                                                // we simulate the window Resize so the charts will get updated in realtime.
                                                var simulateWindowResize = setInterval(function() {
                                                    window.dispatchEvent(new Event('resize'));
                                                }, 180);

                                                // we stop the simulation of Window Resize after the animations are completed
                                                setTimeout(function() {
                                                    clearInterval(simulateWindowResize);
                                                }, 1000);
                                            });

                                            $('.switch-change-color input').on("switchChange.bootstrapSwitch", function() {
                                                var $btn = $(this);

                                                if (white_color == true) {

                                                    $('body').addClass('change-background');
                                                    setTimeout(function() {
                                                        $('body').removeClass('change-background');
                                                        $('body').removeClass('white-content');
                                                    }, 900);
                                                    white_color = false;
                                                } else {

                                                    $('body').addClass('change-background');
                                                    setTimeout(function() {
                                                        $('body').removeClass('change-background');
                                                        $('body').addClass('white-content');
                                                    }, 900);

                                                    white_color = true;
                                                }


                                            });

                                            $('.light-badge').click(function() {
                                                $('body').addClass('white-content');
                                            });

                                            $('.dark-badge').click(function() {
                                                $('body').removeClass('white-content');
                                            });
                                        });
                                    });
                                </script>
                                <script src="https://cdn.trackjs.com/agent/v3/latest/t.js"></script>
                                <script>
                                    window.TrackJS &&
                                        TrackJS.install({
                                            token: "ee6fab19c5a04ac1a32a645abde4613a",
                                            application: "black-dashboard-free"
                                        });
                                </script>
    </body>

    </html>
<?php endif; ?>