<?php
$title = 'Withdrawal History';
// require_once('../admin/lib/table-traits.php'); 
// require_once('../admin/lib/basic-function.php'); 
// require_once('../admin/lib/user-functions.php'); 
require_once('header-links.php');

$current_pg = 5;

$all_withdrawal = $basicFunctn->selectWhereDlt($user->withdrawal_tb, 'user_id', $user_logged['unique_id']);

// print_r($all_withdrawal);
// die();
?>

<body>
    <!-- BEGIN LOADER -->
    <div id="load_screen">
        <div class="loader">
            <div class="loader-content">
                <div class="spinner-grow align-self-center"></div>
            </div>
        </div>
    </div>
    <!--  END LOADER -->

    <!--  BEGIN NAVBAR  -->
    <?php require_once('header.php'); ?>
    <!--  END NAVBAR  -->

    <!--  BEGIN MAIN CONTAINER  -->
    <div class="main-container" id="container">

        <div class="overlay"></div>
        <div class="search-overlay"></div>

        <!--  BEGIN SIDEBAR  -->
        <?php require_once('sidebar.php'); ?>
        <!--  END SIDEBAR  -->

        <!--  BEGIN CONTENT AREA  -->
        <div id="content" class="main-content">
            <div class="layout-px-spacing">

                <div class="row layout-spacing">

                    <!-- Content -->
                    <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 layout-top-spacing">

                        <!-- <div class="user-profile layout-spacing"> -->
                        <div class="widget-content widget-content-area">
                            <div class="table-responsive">
                                <table class="table table-hover mb-4">
                                    <thead>
                                        <tr>
                                            <th>S/N</th>
                                            <th>Withdrawal Id</th>
                                            <th>Category</th>
                                            <th>Amount($)</th>
                                            <th>Coin Invested</th>
                                            <th class="text-center">Status</th>
                                            <th>Date Created</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php  
                                     if(count($all_withdrawal)>0){ 
                                    $i = 1;
                                    foreach ($all_withdrawal as $e) { 
                                        if($e['category'] == 'INTEREST'){
                                            $txn = $basicFunctn->getDataDlt($e['transaction_id'],$basicFunctn->transaction_tb);
                                            $coin = $basicFunctn->getDataDlt($txn['coin_type_id'],$basicFunctn->currencies_tb);
                                        }elseif ($e['category'] == 'BONUS') {
                                            $txn = $basicFunctn->getDataDlt($e['transaction_id'],$basicFunctn->referrer_bonus_tb);
                                            $coin = $basicFunctn->getDataDlt($txn['coin_id'],$basicFunctn->currencies_tb);
                                        }
                                        ?>
                                        <tr>
                                            <td><?php print $i; ?></td>
                                            <td><?php print $e['unique_id']; ?></td>
                                            <td><?php print $e['category']; ?></td>
                                            <td><?php print $e['amt_in_usd']; ?></td>
                                            <td><?php print $coin['name']; ?></td>
                                            <td class="text-center text-capitalize">
                                                <?php if($e['status'] == 'PENDING'){ ?>
                                                    <span class="text-warning">
                                                        <?php print $e['status']; ?>
                                                    </span>
                                                <?php }elseif($e['status'] == 'PAID'){ ?>
                                                    <span class="text-success">
                                                        <?php print $e['status']; ?>
                                                    </span>
                                                <?php }elseif($e['status'] == 'COMPLETED'){ ?>
                                                    <span class="text-danger">
                                                        <?php print $e['status']; ?>
                                                    </span>
                                                <?php } ?>
                                            </td>
                                            <td><?php print $e['created_at']; ?></td>
                                        </tr>
                                    <?php $i++; }
                                         } else{ ?>
                                         <tr> 
                                             <td class="text-center" colspan="7"> No Records Found </td> 
                                         </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!-- </div> -->

                    </div>

                </div>
            </div>
            <?php require_once('footer.php'); ?>
        </div>
        <!--  END CONTENT AREA  -->
    </div>
    <?php require_once('footer-links.php'); ?>
    <script>
        $('.edit_user_btn').click(async function(e) {
            e.preventDefault();
            let edit_user_form = $('.edit_user_form').serializeArray();
            let form_data = set_form_data(edit_user_form);
            // console.log(edit_user_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'profile', 1);
        });
    </script>