<?php
include 'header.php';

?>


<div class="pt-28 md:pt-0 mt-0 md:mt-36 w-full md:w-4/5" id="general-content">
    <div class="w-full md:w-10/12 md:ml-64 2xl:ml-1/5" id="general-content-section">


        <div class="w-full py-5">
            <div class="w-full flex justify-center">
                <div class="w-11/12 rounded-md bg-[#0e1726] p-2 md:p-4">
                    <div class="flex justify-between items-center">
                        <div>

                            <h2 class="bg-transparent text-[#ebedf2] font-medium capitalize">
                                my withdrawals
                            </h2>
                        </div>

                        <div>
                            <a href="dashboard.php"
                                class="flex justify-start items-center text-xs text-gray-400 hover:text-white">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24"
                                    stroke="currentColor" stroke-width="2">
                                    <path stroke-linecap="round" stroke-linejoin="round"
                                        d="M11 17l-5-5m0 0l5-5m-5 5h12" />
                                </svg>
                                <span>back</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>



        <div id="preloader" class="action-preloader">
            <div id="loading-bar-spinner" class="spinner">
                <div class="spinner-icon"></div>
            </div>
        </div>







        <div class="py-5">
            <div class="w-full flex justify-center">
                <div class="w-11/12 rounded-sm bg-[#0e1726] p-4">


                    <div class="w-full py-5">
                        <div
                            class="w-full lg:flex lg:justify-evenly lg:space-x-2 space-y-3 lg:space-y-0 text-[#bfc9d4]">

                        </div>
                    </div>


                    <div class="py-5">
                        <div class="w-full flex justify-center">
                            <div class="w-11/12 rounded-sm bg-[#0e1726] p-1 md:p-4">
                                <?php
                               
                                
                                $query = "SELECT * FROM `withdrawals` WHERE user_id = $user_id";
                                $result = mysqli_query($conn, $query); 
                                
                                if(mysqli_num_rows($result) > 0) {
                                    // Start the table with your original styling
                                    echo '<table id="datatable-skeleton-table" class="text-[#bfc9d4] text-xs md:text-sm">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>Date</th>
                                                    <th>Full Name</th>
                                                    <th>Amount</th>
                                                    <th>Fee</th>
                                                    <th>Method</th>
                                                    <th>Wallet Address</th>
                                                    <th>Status</th>
                                                </tr>
                                            </thead>
                                            <tbody width="100%">';
                                    
                                    $counter = 1;
                                    
                                    // Using do-while loop to fetch and display the data
                                    do {
                                        $row = mysqli_fetch_assoc($result);
                                        if($row) {
                                            // Format the date (assuming created_at is a timestamp)
                                            $date = date("d.m.Y H:i:s", strtotime($row['created_at']));
                                            
                                            // Format the amount
                                            $amount = number_format($row['amount'], 8);
                                            $fee = number_format($row['fee'], 8);
                                            
                                            // Format status (lowercase for consistency with your example)
                                            $status = strtolower($row['status']);
                                            
                                            echo '<tr>
                                                    <td>'.$counter.'</td>
                                                    <td>'.$date.'</td>
                                                    <td>'.htmlspecialchars($row['fullname']).'</td>
                                                    <td>'.$amount.'</td>
                                                    <td>'.$fee.'</td>
                                                    <td>'.htmlspecialchars($row['crypto_method']).'</td>
                                                    <td>'.htmlspecialchars($row['wallet_address']).'</td>
                                                    <td>'.$status.'</td>
                                                  </tr>';
                                            
                                            $counter++;
                                        }
                                    } while($row);
                                    
                                    echo '</tbody></table>';
                                } else {
                                    echo '<p>No withdrawals found.</p>';
                                }
                                
                                // Free the result set
                                mysqli_free_result($result);
                                ?>
                            </div>
                        </div>
                    </div>


                </div>
            </div>

        </div>


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