@extends('layouts.admin')
@section('content')

<!-- start page title -->
<div class="row">
    <div class="col-12">
        <div class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent">
            <h4 class="mb-sm-0">Match Requests from Chat</h4>

            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Home</a></li>
                    <li class="breadcrumb-item active">Match Requests</li>
                </ol>
            </div>
        </div>
    </div>
</div>
<!-- end page title -->

<div class="row">
    <div class="col-lg-12">
        <div class="card" id="orderList">
            <div class="card-header border-0">
                <div class="row align-items-center gy-3">
                    <div class="col-sm">
                        <h5 class="card-title mb-0">Chat-Based Match Requests</h5>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table id="MatchRequestsTable" class="table table-bordered nowrap align-middle" style="width: 100%;">
                        <thead>
                            <tr class="text-uppercase">
                                <th>Sl No</th>
                                <th>Male User</th>
                                <th>Female User</th>
                                <th>Questions Exchanged</th>
                                <th>Match Date</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody class="list form-check-all">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

@endsection
@section('script')
<script>
$(document).ready(function() {
    var table = $('#MatchRequestsTable').DataTable({
        responsive: true,
        paging: true,
        searching: true,
        ordering: true,
        lengthChange: true,
        serverSide: true,
        ajax: {
            url: "{{ route('admin.match.requests.data') }}",
            type: 'GET'
        },
        columns: [
            { data: 'id', name: 'id' },
            { data: 'male_user', name: 'male_user' },
            { data: 'female_user', name: 'female_user' },
            { data: 'questions_exchanged', name: 'questions_exchanged' },
            { data: 'created_at', name: 'created_at' },
            { data: 'action', name: 'action' }
        ],
        columnDefs: [
            {
                orderable: false,
                targets: [0, 5]
            },
            {
                targets: 0,
                render: function(data, type, row, meta) {
                    const pageInfo = $('#MatchRequestsTable').DataTable().page.info();
                    const startIndex = pageInfo.start;
                    return startIndex + meta.row + 1;
                }
            }
        ],
        order: [[4, 'desc']] // Sort by match date descending
    });
});
</script>
@endsection
