@extends('layout.dashboard_chart')
@extends('layout.app')

@section('content')




    @php
        
        // $pCustomer = TopmenuService::countPendingCustomer();
        
        // $counter = TopmenuService::getDashboardCounter();
        
        // $eCustomer = TopmenuService::countExpiredCustomer();
        
        // $mCustomer = TopmenuService::countMonthlyCustomer();
        
        // $closeCustomer = TopmenuService::totalClosedCustomer();
        
        // //
        
        // $allCustomer = TopmenuService::countAllcustomer();
        
        // $allActiveCustomer = TopmenuService::activeCustomer();
        
        // $allDectiveCustomer = TopmenuService::deactivatedCustomer();
    @endphp


    @role('PendingCustomerChecker')
        <div class="col-lg-4 col-6">
            <x-Custom.Countercard link="pendingCustomer" cardtitle="Pending Customer"
                cardcount="{{ $clientCount->where('client_approval', 'pending')->first()->total }}"><i class="fa fa-users"></i>
            </x-custom.Countercard>

        </div>
    @endrole



    @can('show-dashboard')
        <div class="row">
            <div class="col-sm-12">
                <div class="card card-body p-2">

                    <h2 class="text-center">Customer Information</h2>

                    <div class="row">
                        <p style="margin-inline: 10px;">All Customer {{ $allClient ?? 0 }}</p>
                        <div class="col-sm-5" id="customer_info" style="width: 700px; height: 368px;"></div>

                        <div class="col-sm-5" id="accounts_info" style="width: 800px; height: 300px;"></div>

                    </div>
                </div>

            </div>



            <div class="col-sm-12 col-lg-12" style="text-align: center">
                <div class="card card-body p-0">
                    <div class="row">
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-info"
                                href="{{ route('clients.index') }}"><span class="badge bg-purple"
                                    id="counter">{{ $allClient ?? 0 }}</span><i class="fa fa-users"></i>
                                Clients</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-success"
                                href="{{ route('activeCustomer') }}"><span class="badge bg-danger"
                                    id="counter">{{ $clientCount->where('clients_status', 'active')->first()->total ?? 0 }}</span><i
                                    class="fa fa-check"></i> Active Clients</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-secondary"
                                href="{{ route('deactivatedClients') }}"><span class="badge bg-success"
                                    id="counter">{{ $clientCount->where('clients_status', 'deactive')->where('client_approval', 'approved')->first()->total ?? 0 }}</span><i
                                    class="fa fa-exclamation"></i> Deactive Clients</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-primary"
                                href="{{ route('newJoin') }}"><span class="badge bg-secondary"
                                    id="counter">{{ $newClients ?? 0 }}</span><i class="fa fa-user"></i> New Clients</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-purple"
                                href="{{ route('expiredClients') }}"><span class="badge bg-warning"
                                    id="counter">{{ $clientCount->where('clients_status', 'expired')->where('client_approval', 'approved')->first()->total ?? 0 }}</span><i
                                    class="fa fa-times"></i>
                                Expire Clients</a></div>

                        <div class="col-sm-6 col-lg-2" style="width: auto">
                            <a class="btn1 btn-app bg-danger" href="{{ route('pendingCustomer') }}">
                                <span class="badge bg-primary"
                                    id="counter">{{ $clientCount->where('client_approval', 'pending')->first()->total ?? 0 }}</span>
                                <i class="fa fa-pause-circle"></i>
                                Pending Clients</a>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-6 col-lg-2" style="width: auto">
                            <a class="btn1 btn-app bg-purple"><span class="badge bg-info" id="counter">0</span><i
                                    class="fa fa-minus-square"></i> Today
                                Expense</a>
                        </div>
                        <div class="col-sm-6 col-lg-2" style="width: auto">
                            <a class="btn1 btn-app bg-dark"><span class="badge bg-purple"
                                    id="counter">{{ $thisMonthBillGenerate ?? 0 }}</span><i
                                    class="fa fa-credit-card"></i>{{ date('M Y') }} Bill</a>
                        </div>
                        <div class="col-sm-6 col-lg-2" style="width: auto">
                            <a class="btn1 btn-app bg-warning"><span class="badge bg-secondary"
                                    id="counter">{{ $thisMonthBillPaid ?? 0 }}</span><i class="fa fa-credit-card"></i>
                                {{ date('M Y') }} Col</a>
                        </div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-success"><span
                                    class="badge bg-info" id="counter">{{ $totalPaid ?? 0 }}</span><i
                                    class="fa fa-check-circle"></i> Total Bill COL</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-secondary"><span
                                    class="badge bg-success" id="counter">{{ $previous_due ?? 0 }}</span><i
                                    class="fa fa-exclamation-triangle"></i> Previous Dues</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-light"><span
                                    class="badge bg-secondary" id="counter">{{ $total_due ?? 0 }}</span><i
                                    class="fa fa-minus-square"></i> Total Dues</a></div>
                    </div>

                    <div class="row">
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-danger"
                                href="{{ url('admin/list/close-list') }}"><span class="badge bg-info"
                                    id="counter">{{ $closeClient ?? 0 }}</span><i class="fa fa-times"></i> Closed
                                Clients</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-secondary"><span
                                    class="badge bg-purple" id="counter">{{ $currentMonthDue ?? 0 }}</span><i
                                    class="fa fa-credit-card"></i>{{ date('F Y') }} Due</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-light"><span
                                    class="badge bg-secondary" id="counter">{{ $currentMonthBillDiscount ?? 0 }}</span><i
                                    class="fa fa-credit-card"></i> {{ date('F Y') }} Dis</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-info"><span
                                    class="badge bg-purple" id="counter">0</span><i class="fa fa-bars"></i> Total
                                Income</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-purple"><span
                                    class="badge bg-success" id="counter">0</span><i class="fa fa-minus-square"></i> Total
                                Expense</a></div>
                        <div class="col-sm-6 col-lg-2" style="width: auto"><a class="btn1 btn-app bg-secondary"><span
                                    class="badge bg-purple" id="counter">0</span><i class="fa fa-folder-open"></i> Closed
                                Tokens</a></div>
                    </div>
                </div>


            </div>

        </div>

        <div class="row">


            @include('dashboard.billreport')



            <div class="col-sm-12">
                <div class="card p-2">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead class="bg-gray-50">
                                <tr>
                                    <p>Reseller Information</p>
                                    <th scope="col">
                                        ID
                                    </th>
                                    <th scope="col">
                                        Name
                                    </th>
                                    <th scope="col">
                                        Balance
                                    </th>

                                    <th style="text-align: center">
                                        POP
                                    </th>





                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">


                                @foreach ($resellers as $r)
                                    <tr>
                                        <td class="whitespace-nowrap">
                                            {{ $r->id }}
                                        </td>
                                        <td class="whitespace-nowrap">
                                            {{ $r->name }}
                                        </td>
                                        <td class="whitespace-nowrap">
                                            {{ $r->balance[0]['amount'] ?? 0 }}
                                        </td>

                                        <td class="whitespace-nowrap" style="padding: 0px; margin: 0px;">
                                            <table class="table" style="padding: 0; margin:0px;">



                                                @foreach ($r->pops as $pop)
                                                    @if ($pop->reseller_id == $r->id)
                                                        <tr>
                                                            <td style="width: 50%">
                                                                {{ $pop->popname }}
                                                            </td>
                                                            <td style="width: 50%">

                                                                @if (!empty($pop->balance->first()))
                                                                    {{ $pop->balance->first()->amount }}
                                                                @else
                                                                    0
                                                                @endif


                                                            </td>


                                                        </tr>
                                                    @endif
                                                @endforeach


                                            </table>



                                        </td>




                                    </tr>
                                @endforeach



                                <!-- More items... -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>




        </div>
    @endcan

    @can('token-dashboard')
        <div class="row">
            @include('dashboard.token')

        </div>
    @endcan

    {{-- @role('Reseller Admin') --}}

    @include('dashboard.reseller')


    @include('dashboard.sub-reseller')




    </div>
    <style>
        .btn-app {
            border-radius: 3px;
            background-color: #f8f9fa;
            border: 1px solid #ddd;
            color: #6c757d;
            font-size: 12px;
            height: 70px;
            margin: 0 0 10px 10px;
            min-width: 80px;
            padding: 15px 5px;
            position: relative;
            text-align: center;
        }

        .btn1 {
            display: inline-block;
            font-weight: 400;
            color: #212529;
            text-align: center;
            vertical-align: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            background-color: transparent;
            border: 1px solid transparent;
            padding: 0.375rem 0.75rem;
            font-size: 1rem;
            line-height: 1.5;
            width: 150px;
            height: 70px;
            border-radius: 0.25rem;
            transition: color .15s ease-in-out,
                background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
        }

        a {
            color: #007bff;
            text-decoration: none;
            background-color: transparent;
        }

        #counter {
            font-size: 15px;
        }
    </style>
@endsection
