<x-app-layout>
    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">

            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900">

                    {{-- Header --}}
                    <div class="flex items-center justify-between mb-6">
                        <h1 class="text-2xl font-bold">Students</h1>

                        <a href="{{ route('admin.students.create') }}"
                           class="inline-block bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md">
                            + Add Student
                        </a>
                    </div>

                    {{-- Table --}}
                    @if($students->isEmpty())
                        <p>No students found.</p>
                    @else
                        <div class="overflow-x-auto">
                            <table class="table-auto w-full border-collapse border border-gray-300">
                                <thead>
                                    <tr class="bg-gray-100">
                                        <th class="border border-gray-300 px-4 py-2 text-left">Name</th>
                                        <th class="border border-gray-300 px-4 py-2 text-left">Email</th>
                                        <th class="border border-gray-300 px-4 py-2 text-left">Billing Account</th>
                                        <th class="border border-gray-300 px-4 py-2 text-left">Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($students as $student)
                                        <tr>
                                            <td class="border border-gray-300 px-4 py-2">
                                                {{ $student->user->first_name }} {{ $student->user->last_name }}
                                            </td>

                                            <td class="border border-gray-300 px-4 py-2">
                                                {{ $student->user->email }}
                                            </td>

                                            <td class="border border-gray-300 px-4 py-2">
                                                @if ($student->billingAccount)
                                                    {{ $student->billingAccount->name }}
                                                @else
                                                    <span class="text-gray-400">None</span>
                                                @endif
                                            </td>

                                            <td class="border border-gray-300 px-4 py-2">
                                                <a href="{{ route('admin.students.edit', $student->id) }}"
                                                   class="text-blue-600 hover:text-blue-800">
                                                    Edit
                                                </a>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @endif

                </div>
            </div>

        </div>
    </div>
</x-app-layout>
