@extends('layout.app')

@section('content')
    <div class="card">
        <div class="card-body">
            @php
                use App\Models\Client;
            @endphp

            <div class="table-responsive">
                <div>
                    <button id="downloadBtn" class="btn btn-primary">Download In Excele</button>
                    {{-- <button href= "route('expireButnotDisconectProciede')">Disconect</button> --}}
                    <a href="{{ route('expireButnotDisconectProciede') }}" class="dropdown-item">Disconnect</a>

                    {{-- <button id="printBtn" class="btn btn-primary">Print</button> --}}
                </div>
                <div class="print-content" id="result">
                    <div class="print-content" id="result">
                        <table class="table table-bordered table-condensed table-striped" id="tableId">
                            <thead class="bg-dark">
                                <tr>
                                    <th>
                                        User Name
                                    </th>
                                    <th>
                                        Ip
                                    </th>

                                    <th>Pop (Manger)</th>
                                </tr>
                            </thead>

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

                                @foreach ($clients as $client)
                                    <tr>

                                        <td>
                                            {{ $client->username }}
                                        </td>
                                        <td>
                                            {{ $client->framedipaddress }}
                                        </td>
                                        @php
                                            $clientTable = Client::with(['pop.reseller'])
                                                ->where('userid', $client->username)
                                                ->first();

                                            if (!$clientTable || !$clientTable->pop) {
                                                $name = '';
                                            } else {
                                                $popName = $clientTable->pop->popname ?? '';
                                                $resellerName = $clientTable->pop->reseller->name ?? '';
                                                $name = trim("{$popName} ({$resellerName})");
                                            }
                                        @endphp
                                        <td>{{ $name }}</td>


                                    </tr>
                                @endforeach

                            </tbody>

                            <tfoot>
                                <tr>
                                    <th colspan="1" class="text-right">{{ $clients->count() }}</th>
                                </tr>
                            </tfoot>

                        </table>
                    </div>

                </div>
            </div>

        </div>
    </div>

    <style>
        @media print {
            body * {
                visibility: hidden;
            }

            .no-page-break {
                page-break-inside: avoid !important;
            }

            .print-content,
            .print-content * {
                visibility: visible;
            }

            .print-content {
                position: absolute;
                left: 10px;
                top: 0;
            }

            .print-content table {
                width: 100%;
                border-collapse: collapse;
                font-size: 16pt;
            }

            .print-content th,
            .print-content tr,
            .print-content td {
                padding: 8px;
                font-size: 14pt !important;
                font-weight: bold;
            }

            .print-content th {
                background-color: #f2f2f2;
                /* Optionally set a background color for table headers */
            }

            .print-content td {
                border: 1px solid #ddd;
                /* Optionally add borders to table cells */
            }

            .no-print {
                display: none;
            }
        }
    </style>
@endsection



@section('ajax')
    <script src="{{ asset('/') }}js/xlsx/xlsx.full.min.js"></script>
    <script src="{{ asset('/') }}js/html2pdf/html2pdf.bundle.min.js"></script>
    <script></script>
@endsection
