<section class="section py-2">
    <div class="row g-2 mb-3">
        
        <div class="col-12 col-md-6 col-xl-3">
            <div class="card border-0 custom-simple-card" style="border-radius: 8px; background-color: #ffffff;">
                <div class="card-body d-flex align-items-center p-3">
                    <div class="d-flex align-items-center justify-content-center rounded-2 me-3" style="width: 40px; height: 40px; background-color: #f1f5f9;">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#475569" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width: 18px; height: 18px;">
                            <rect x="2" y="5" width="20" height="14" rx="2" ry="2"></rect>
                            <line x1="2" y1="10" x2="22" y2="10"></line>
                        </svg>
                    </div>
                    <div>
                        <span class="text-muted d-block small" style="color: #64748b !important;">Account Balance</span>
                        <h4 class="fw-bold text-dark m-0" style="font-size: 18px;">
                            ৳<?= current_user('balance'); ?>
                        </h4>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-6 col-xl-3">
            <div class="card border-0 custom-simple-card" style="border-radius: 8px; background-color: #ffffff;">
                <div class="card-body d-flex align-items-center p-3">
                    <div class="d-flex align-items-center justify-content-center rounded-2 me-3" style="width: 40px; height: 40px; background-color: #f1f5f9;">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#475569" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width: 18px; height: 18px;">
                            <polyline points="20 6 9 17 4 12"></polyline>
                        </svg>
                    </div>
                    <div>
                        <span class="text-muted d-block small" style="color: #64748b !important;">Success Trx</span>
                        <h4 class="fw-bold text-dark m-0 success_trx" style="font-size: 18px;">0</h4>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-6 col-xl-3">
            <div class="card border-0 custom-simple-card" style="border-radius: 8px; background-color: #ffffff;">
                <div class="card-body d-flex align-items-center p-3">
                    <div class="d-flex align-items-center justify-content-center rounded-2 me-3" style="width: 40px; height: 40px; background-color: #f1f5f9;">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#475569" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width: 18px; height: 18px;">
                            <circle cx="12" cy="12" r="10"></circle>
                            <polyline points="12 6 12 12 16 14"></polyline>
                        </svg>
                    </div>
                    <div>
                        <span class="text-muted d-block small" style="color: #64748b !important;">Pending Trx</span>
                        <h4 class="fw-bold text-dark m-0 pending_trx" style="font-size: 18px;">0</h4>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-6 col-xl-3">
            <div class="card border-0 custom-simple-card" style="border-radius: 8px; background-color: #ffffff;">
                <div class="card-body d-flex align-items-center p-3">
                    <div class="d-flex align-items-center justify-content-center rounded-2 me-3" style="width: 40px; height: 40px; background-color: #f1f5f9;">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#475569" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width: 18px; height: 18px;">
                            <line x1="18" y1="20" x2="18" y2="10"></line>
                            <line x1="12" y1="20" x2="12" y2="4"></line>
                            <line x1="6" y1="20" x2="6" y2="14"></line>
                        </svg>
                    </div>
                    <div>
                        <span class="text-muted d-block small" style="color: #64748b !important;">Gross Earnings</span>
                        <h4 class="fw-bold text-dark m-0 earning" style="font-size: 18px;">0</h4>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <div class="row">
        <div class="col-12">
            <div class="card border-0 custom-simple-card" style="border-radius: 8px; background-color: #ffffff;">
                <div class="card-header bg-white border-0 pt-3 pb-1 d-flex justify-content-between align-items-center">
                    <span class="fw-bold text-dark" style="font-size: 14px;">Recent Transactions</span>
                    
                    <div class="dropdown">
                        <button class="btn btn-sm dropdown-toggle fw-medium px-2.5 py-1" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false" style="border: 1px solid #cbd5e1; font-size: 12px; background-color: #fff; color: #475569; border-radius: 6px;">
                            Filter
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end border-0 shadow-sm" aria-labelledby="dropdownMenuButton" style="padding: 4px; min-width: 120px; border-radius: 6px; border: 1px solid #e2e8f0;">
                            <li><a href="#" class="dropdown-item mydrp active rounded py-1 small" data-period="today" style="font-size: 12px;">Today</a></li>
                            <li><a href="#" class="dropdown-item mydrp rounded py-1 small" data-period="week" style="font-size: 12px;">This Week</a></li>
                            <li><a href="#" class="dropdown-item mydrp rounded py-1 small" data-period="month" style="font-size: 12px;">This Month</a></li>
                            <li><a href="#" class="dropdown-item mydrp rounded py-1 small" data-period="year" style="font-size: 12px;">This Year</a></li>
                        </ul>
                    </div>
                </div>

                <div class="card-body pt-1">
                    <div id="top-5-scroll" class="px-0" style="height: 280px; overflow-y: auto;">
                        <ul id="type-list" class="list-unstyled mb-0">
                            </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
    /* সিম্পল বর্ডার গাইডলাইন (কোনো ভারী শ্যাডো নেই) */
    .custom-simple-card {
        border: 1px solid #e2e8f0 !important;
    }
    .dropdown-menu .mydrp.active {
        background-color: #3b82f6 !important;
        color: #ffffff !important;
    }
    #top-5-scroll::-webkit-scrollbar {
        width: 3px;
    }
    #top-5-scroll::-webkit-scrollbar-track {
        background: #f1f5f9;
    }
    #top-5-scroll::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 4px;
    }
</style>

<script>
    function get_dashboard_values(period) {
        $.post("<?= user_url('dashboard-data') ?>", {
            token: token,
            period: period
        }, function(result) {
            var data = jQuery.parseJSON(result);
            $.each(data, function(index, element) {
                $("." + index).html(element);
            });
            $('#type-list').html(data.listItems);
        });
    }

    $(document).ready(function() {
        var initialPeriod = $('.mydrp.active').data('period');
        get_dashboard_values(initialPeriod);
        
        $('.mydrp').on('click', function(e) {
            e.preventDefault();
            $('.mydrp').removeClass('active');
            $(this).addClass('active');
            
            var selectedText = $(this).text();
            $('#dropdownMenuButton').text(selectedText);
            
            var period = $(this).data('period');
            get_dashboard_values(period);
        });
    });
</script>
