<div class="col-md-2">Search Total: {{ $list->total() }}</div>
{{-- <div class="col-md-6">
    {{ $list->onEachSide(1)->links() }}
</div> --}}

<table class="table table-bordered table-striped table-condensed">
    <thead>
        <tr>
            <th>SL</th>
            <th>ID</th>
            <th>User name</th>
            <th>Status</th>
            <th>Expire</th>
            <th>Bill Info</th>
            <th>Package</th>
            <th>POP</th>
            <th>Name</th>
            <th>Contact</th>
            <th style="width:350px">User Info</th>
            <th>Created Date</th>
            <th scope="col" class="noprin">Action</th>
        </tr>
    </thead>
    <tbody>
        @foreach ($list as $r)
            <tr @if ($r->clients_status == 'deactive') class="deactive" @endif>
                <td>{{ $loop->iteration }}</td>
                <td class="text-center">
                    <a class="btn btn-info btn-block btn-xs"
                        href="{{ route('getPaymentHistory', $r->id) }}">@php(printf('CID%04d', $r->id))</a>
                    @if (!checkAPI())
                        <a href="{{ route('getCustomerLogHistory', $r->userid) }}" class="noprint btn btn-primary btn-xs btn-block">Log</a>
                    @endif
                </td>
                <td class="no-wrap">
                    {{ $r->userid }}
                    <br>
                    {{ $r->password }}
                    {{-- <br>
                    @if (isset($online) && in_array($r->userid, $online))
                        <span class="btn btn-success btn-xs">Online</span>
                    @else
                        <span class="btn btn-danger btn-xs">Ofline</span>
                    @endif --}}
                </td>
                @if ($r->deleted_at != null)
                    <td class="deactive bg-danger">
                        Closed
                    </td>
                @elseif ($r->clients_status == 'expired')
                    <td class="deactive bg-danger">
                        <x-Custom.Status status="{{ $r->clients_status }}" />
                    </td>
                @elseif($r->clients_status == 'deactive')
                    <td class="deactive bg-danger">
                        <x-Custom.Status status="{{ $r->clients_status }}" />
                    </td>
                @elseif($r->clients_status == 'active')
                    <td class="bg-success">
                        <x-Custom.Status status="{{ $r->clients_status }}" />
                    </td>
                @elseif($r->clients_status == 'disable')
                    <td class="bg-warning">
                        <x-Custom.Status status="{{ $r->clients_status }}" />
                    </td>
                @elseif($r->client_approval == 'pending')
                    <td>
                        {{ $r->client_approval }}
                    </td>
                @else
                    <td>
                        <x-Custom.Status status="{{ $r->clients_status }}" />
                    </td>
                @endif
                @if ($r->clients_status == 'expired')
                    <td class="bg-danger whitespace-nowrap">
                        {{ date('d-M-Y', strtotime($r->expire_date)) }}
                    </td>
                @else
                    <td class="bg-success whitespace-nowrap">
                        {{ date('d-M-Y', strtotime($r->expire_date)) }}
                    </td>
                @endif
                <td style="min-width:130px">
                    <p style="font-size:14px;">
                        B Cycle: {{ $r->billing_cycle }} <br>
                        @if (isset($r->pop->bill_generate) && $r->pop->bill_generate == 'yes')
                            B Amount: @role('Sub Reseller')
                                @if ($r->pop->subreseller == 'yes')
                                    {{ $r->subpack->sub_package_rate }}
                                @else
                                    {{ $r->packages->package_rate }}
                                @endif
                            @else
                                {{ $r->packages->package_rate }}
                            @endrole <br>
                            OTC : {{ $r->clientsinfo->otc }} <br>
                            @if ($r->clientsinfo->otc_due > 0)
                                <span class="bg-danger pl-1 pr-1"> OTC Due: {{ $r->clientsinfo->otc_due }}</span>
                            @endif
                        @endif
                    </p>
                </td>
                <td class="no-wrap">
                    @can('show-sub-package')
                        <span class="badge badge-info">{{ $r->subpack->name ?? '' }}</span>
                    @endcan
                    @can('show-mother-package')
                        <span class="badge badge-info"> {{ $r->packages->package_name ?? '' }}</span>
                    @endcan
                </td>
                <td class="no-wrap">
                    {{ $r->pop->popname ?? '' }}
                </td>
                <td>
                    {{ $r->clientsinfo->clients_name ?? '' }}
                </td>
                <td>
                    {{ $r->clientsinfo->contact_no ?? '' }}
                </td>
                <td style="width:350px;">
                    <p style="font-size:14px;">
                        Flat No: {{ $r->clientsinfo->flat_no ?? '' }} ,
                        Building Name: {{ $r->clientsinfo->building_name ?? '' }} ,<br>
                        Road No: {{ $r->clientsinfo->road_no ?? '' }} ,<br>
                        Block/Sector: {{ $r->clientsinfo->block_sector ?? '' }} ,
                        Area : {{ $r->clientsinfo->area ?? '' }} ,
                        Latitude : {{ $r->clientsinfo->client_latitude ?? '' }} ,
                        Longitude : {{ $r->clientsinfo->client_longitude ?? '' }} </p>

                        @if ($r->marketed_by != 0 && $r->marketed_by != '')
                        <span class="badge badge-info">Marketed BY: {{ marketedBy($r->marketed_by) }}</span>
                    @endif
                </td>
                <td class="whitespace-nowrap">
                    {{ date('d-M-Y h:i:sa', strtotime($r->created_at)) }}
                </td>
                <td class="text-center noprint" style="width:160px;">
                    @if ($r->deleted_at != null)
                    @else
                        <div class="dropdown">
                            <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton"
                                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                Action
                            </button>
                            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                <a href="{{ route('clients.show', $r->id) }}" class="dropdown-item">Details</a>
                                @can('mac-customer_edit')
                                    <a href="{{ route('clients.edit', $r->id) }}" class="dropdown-item">Edit</a>
                                @endcan
                                @can('changeBillCycle')
                                    <button type="button" class="dropdown-item clientBillCycleChange" data-toggle="modal"
                                        data-id="{{ $r->id }}" data-curdate={{ $r->billing_cycle }}
                                        data-target="#billCycleChange">
                                        Bill Cycle Change
                                    </button>
                                @endcan
                                <div class="mb-1"></div>
                                @if ($r->client_approval == 'pending')
                                    @can('new-customer-approve')
                                        <form method="POST" action="{{ route('clinetApprove', $r->id) }}">
                                            @method('post')
                                            @csrf
                                            <input type="hidden" name="user_approve" value="{{ $r->id }}">
                                            <button
                                                onclick="return confirm('Are you sure you want to Approved this user ?');"
                                                type="submit" class="dropdown-item">Approve</button>
                                        </form>
                                    @endcan
                                @endif
                                @if ($r->clients_status == 'disable')
                                    @can('id-enable')
                                        <a href="{{ route('idEnable', $r->id) }}"
                                            onclick="return confirm('Are you sure you want to Enable the ID?');"
                                            class="dropdown-item">Enable</a>
                                    @endcan
                                @endif
                                @if ($r->clients_status == 'active')
                                    @can('id-disable')
                                        <a href="{{ route('idDisable', $r->id) }}"
                                            onclick="return confirm('Are you sure you want to Disable the ID?');"
                                            class="confirmDisable dropdown-item">Disable</a>
                                    @endcan
                                @endif
                                <a href="{{ route('close', $r->id) }}"
                                    onclick="return confirm('Are you sure you want to Close the ID?');"
                                    class="confirmDisable dropdown-item">Close</a>
                                @can('mac-customer_destroy')
                                    <form method="POST" action="{{ route('clients.destroy', $r->id) }}">
                                        @method('DELETE')
                                        @csrf
                                        <button onclick="return confirm('Are you sure you want to Delete this user ?');"
                                            type="submit" class="dropdown-item">Delete</button>
                                    </form>
                                @endcan
                            </div>
                        </div>
                    @endif
                </td>
            </tr>
        @endforeach
    </tbody>
</table>


