<style>
    .badge {
        line-height: 1.95;
        font-size: small;
    }
</style>
{{-- @dd($pendingItems) --}}
<x-admin.layout>
    <x-slot name="title">Pending List</x-slot>
    <x-slot name="heading">Pending List</x-slot>

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                </div>
                <div class="card-body">
                    <div class="table-responsive">

                        <table id="buttons-datatables" class="table table-bordered nowrap align-middle" style="width:100%">
                            <thead>
                                <tr>
                                    <th>Sr.No</th>
                                    <th>Application.No</th>
                                    <th>Applicant Name</th>
                                    <th>Service ID</th>
                                    <th>Date</th>
                                    <th>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($pendingItems as $pro )
                                    <tr data-id="{{ $pro->status()->where('service_id', $pro->service_id)->first()?->id }}">
                                        <td>{{ $loop->iteration }}</td>
                                        <td>{{ $pro->application_no }}</td>
                                        <td>{{ $user->where('id', $pro->user_id)->first()?->name }}</td>
                                        <td title="{{ $serviceName->where('service_id', $pro->service_id)->first()?->service_name }}">
                                        {{ \Illuminate\Support\Str::limit($serviceName->where('service_id', $pro->service_id)->first()?->service_name, 30) }}
                                        </td>
                                        <td>{{ isset($pro->created_at) ? date('d-m-Y h:i A', strtotime($pro->created_at)) : 'N/A' }}</td>
                                        <td>
                                            @if ($pro->status()->where('service_id', $pro->service_id)->first()?->id)
                                            <a href="{{ array_key_exists($pro->service_id, $editRoute) && $editRoute[$pro->service_id] != '' ? route($editRoute[$pro->service_id], encrypt($pro->id)) : '#' }}"
                                               class="btn btn-primary">View</a>
                                            @else
                                                -
                                            @endif

                                                {{-- @php
                                                    $serviceId = $pro->status()->where('service_id', $pro->service_id)->first()?->service_id;
                                                @endphp

                                                @if ($serviceId == '187' || $serviceId == '2032')
                                                    <a href="{{ array_key_exists($pro->service_id, $demandnote) && $demandnote[$pro->service_id] != '' ? route($demandnote[$pro->service_id], encrypt($pro->id)) : '#' }}"
                                                    class="btn btn-primary">Demand Note</a>
                                                @else

                                                @endif --}}


                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>

                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>


</x-admin.layout>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
{{-- <script>
    $(document).ready(function () {
        // Approve Button Click
        $('.approveBtn').on('click', function () {
            let statusId = $(this).data('id');

            $.ajax({
                url: '/approve-item/' + statusId,
                type: 'POST',
                data: {
                    _token: '{{ csrf_token() }}'
                },
                success: function (response) {
                    Swal.fire({
                        icon: 'success',
                        title: 'Success!',
                        text: response.message,
                        confirmButtonText: 'OK'
                    }).then(() => {
                        window.location.href = response.redirect_url;
                    });
                },
                error: function (xhr) {
                    Swal.fire({
                        icon: 'error',
                        title: 'Error!',
                        text: 'Error: ' + xhr.responseText,
                        confirmButtonText: 'OK'
                    });
                }
            });
        });

        // Reject Button Click
        $('.rejectBtn').on('click', function () {
            let statusId = $(this).data('id');

            $.ajax({
                url: '/reject-item/' + statusId,
                type: 'POST',
                data: {
                    _token: '{{ csrf_token() }}'
                },
                success: function (response) {
                    Swal.fire({
                        icon: 'success',
                        title: 'Success!',
                        text: response.message,
                        confirmButtonText: 'OK'
                    }).then(() => {
                        window.location.href = response.redirect_url;
                    });
                },
                error: function (xhr) {
                    Swal.fire({
                        icon: 'error',
                        title: 'Error!',
                        text: 'Error: ' + xhr.responseText,
                        confirmButtonText: 'OK'
                    });
                }
            });
        });
    });
</script>
 --}}

