<?php
require '../../app/Controllers/sessions.php';
require '../../app/Controllers/security_admin.php';
require '../../app/Controllers/adminInfos.php';
require 'with.php';

ini_set("display_errors", 0);

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

$toastMessage = $_SESSION['toast_message'];
$toastType = $_SESSION['toast_type'];
unset($_SESSION['toast_message'], $_SESSION['toast_type']);
?>
<!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="../assets/img/apple-icon.png">
    <link rel="icon" type="image/png" href="../assets/img/favicon.png">
    <title>
        TRYBE IGAMING
    </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">
    <link rel="stylesheet" href="../assets/css/build/tailwind.css" />
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <!-- Nucleo Icons -->
    <link href="assets/css/nucleo-icons.css" rel="stylesheet" />
    <!-- CSS Files -->
    <link href="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="assets/demo/demo.css" rel="stylesheet" />
</head>

<body class="">


    <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="./index.php">
                            <i class="tim-icons icon-chart-pie-36"></i>
                            <p>Dashboard</p>
                        </a>
                    </li>
                    <li>
                        <a href="./configs.php">
                            <i class="tim-icons icon-atom"></i>
                            <p>Configurações Gerais</p>
                        </a>
                    </li>
                     <li>
                        <a href="./administer_users.php">
                            <i class="tim-icons icon-single-02"></i>
                            <p>Usuários</p>
                        </a>
                    </li>
                     <li>
                        <a href="./cupons.php">
                            <i class="tim-icons icon-align-center"></i>
                            <p>Cupons</p>
                        </a>
                    </li>
                    <li>
                        <a href="./administer_products.php">
                            <i class="tim-icons icon-align-center"></i>
                            <p>Produtos</p>
                        </a>
                    </li>
                    <li class="active">
                        <a href="./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)">Área de Saques Pendentes</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-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title"> Pendentes</h4>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table tablesorter " id="">
                                        <thead class=" text-[#005E60]">
                                            <tr>
                                                <th class="text-center">
                                                    ID Transação
                                                </th>
                                                <th class="text-center">
                                                    ID Usuário
                                                </th>
                                                <th class="text-center">
                                                    Tefone
                                                </th>
                                                <th class="text-center">
                                                    CPF Beneficiário
                                                </th>
                                                <th class="text-center">
                                                    Chave PIX Beneficiário
                                                </th>
                                                <th class="text-center">
                                                    Tipo de Chave
                                                </th>
                                                <th class="text-center">
                                                    Valor
                                                </th>
                                                <th class="text-center">
                                                    Status
                                                </th>
                                                <th class="text-center">
                                                    Data Criação
                                                </th>
                                                <th class="text-center">
                                                    Ações
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($resultWithdrawalPending as $withdrawal) : ?>
                                                <tr>
                                                    <td class="text-center">
                                                        <?= htmlspecialchars($withdrawal['id']) ?>
                                                    </td>
                                                    <td class="text-center">
                                                        <?= htmlspecialchars($withdrawal['user_id']) ?>
                                                    </td>
                                                    <td class="text-center">
                                                        <?= htmlspecialchars($withdrawal['phone']) ?>
                                                    </td>
                                                    <td class="text-center">
                                                        <?= htmlspecialchars($withdrawal['cpf_beneficiary']) ?>
                                                    </td>
                                                    <td class="text-center">
                                                        <?= htmlspecialchars($withdrawal['key_beneficiary']) ?>
                                                    </td>
                                                    <td class="text-center">
                                                        <?= htmlspecialchars($withdrawal['type_pix']) ?>
                                                    </td>
                                                    <td class="text-center">
                                                        R$ <?= htmlspecialchars(number_format($withdrawal['value'], 2, ',', '.')) ?>
                                                    </td>
                                                    <td class="text-center">
                                                        <span class="badge badge-<?= $withdrawal['status'] == 'pending' ? 'warning' : 'danger' ?>">
                                                            <?= $withdrawal['status'] == 'pending' ? 'Pendente' : 'Desativado' ?>
                                                        </span>
                                                    </td>
                                                    <td class="text-center">
                                                        <?= htmlspecialchars($withdrawal['created_at']) ?>
                                                    </td>
                                                    <td class="text-center flex gap-2">
                                                        <form method="POST">
                                                            <input name="id_with" value="<?= $withdrawal['id'] ?>" type="hidden">
                                                            <button name="payment_pix" type="submit" name="edit_user" class="btn btn-sm btn-success me-1">
                                                                <i class="bx bx-edit"></i> Aprovar
                                                            </button>
                                                        </form>
                                                        <form method="POST">
                                                            <input type="hidden" name="id_product" value="<?= $withdrawal['id'] ?>">
                                                            <button type="submit" name="delete_user" class="ml-2 btn btn-sm btn-danger" onclick="return confirm('Tem certeza que deseja excluir este produto?');">
                                                                <i class="bx bx-trash"></i> Recusar
                                                                </buttom>
                                                        </form>
                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                        </tbody>
                                    </table>
                                    <?php if (!$resultWithdrawalPending) :?>
                                      <p style="margin: 0 auto;text-align:center;margin-top:60px;margin-bottom: 60px;">Nenhum saque pendente até o momento.</p>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </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>

            <?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 elseif ($toastType === 'info') : ?>
                    <div
                        id="toast"
                        class="fixed bottom-4 right-4 z-50 bg-warning 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; ?>

            <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>

            <script>
                function fecharModal() {
                    const modal = bootstrap.Modal.getInstance(document.getElementById('modalConfig'));
                    setTimeout(() => {
                        modal.hide();
                    }, 300); // pequeno delay para evitar conflito com submissão
                }
            </script>
            <!--   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>
                function formatarMoeda(campo) {
                    let valor = campo.value.replace(/\D/g, "");
                    valor = (valor / 100).toFixed(2) + '';
                    valor = valor.replace(".", ",");
                    valor = valor.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
                    campo.value = valor;
                }

                $(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');
                        });
                    });
                });

                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);
                }
            </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>