@extends('layouts.student')
@section('title', 'Messages')
@section('content')
    <x-page-head title="Messages" subtitle="Inbox">
        <x-slot:actions>
            @if ($canCompose ?? false)
                <a href="{{ route('student.messages.create') }}" class="btn btn-primary">Notify Students</a>
            @endif
        </x-slot:actions>
    </x-page-head>
    <x-panel>
        @if ($inbox->isEmpty())
            <x-empty-state title="No messages" message="Your inbox is empty." />
        @else
            <div class="table-wrap"><table><thead><tr><th>From</th><th>Subject</th><th>Date</th><th></th></tr></thead><tbody>
                @foreach ($inbox as $row)
                    <tr>
                        <td>{{ $row->message?->sender?->name ?? '—' }}</td>
                        <td>{{ $row->message?->subject ?? 'No subject' }} @if(!$row->read_at)<span class="badge">New</span>@endif</td>
                        <td>{{ $row->message?->sent_at?->format('d M Y') }}</td>
                        <td class="text-right"><a href="{{ route('student.messages.show', $row) }}" class="btn btn-ghost btn-sm">Open</a></td>
                    </tr>
                @endforeach
            </tbody></table></div>
            <div style="margin-top:16px;">{{ $inbox->links() }}</div>
        @endif
    </x-panel>
@endsection
