@extends('layouts.parent')
@section('title', 'Message')
@section('content')
    @php($message = $messageRecipient->message)
    <x-page-head title="{{ $message?->subject ?? 'Message' }}" subtitle="{{ optional($message?->sent_at)->format('d M Y H:i') }}">
        <x-slot:actions>
            @if ($messageRecipient->read_at === null)
                <form method="POST" action="{{ route('parent.messages.read', $messageRecipient) }}">
                    @csrf
                    <button type="submit" class="btn btn-outline btn-sm">Mark as Read</button>
                </form>
            @endif
        </x-slot:actions>
    </x-page-head>
    <x-panel>
        <p style="color:var(--text2); margin-bottom:12px;">
            From: {{ $message?->sender?->name ?? 'School' }}
        </p>
        <div style="white-space:pre-wrap;">{{ $message?->body }}</div>
    </x-panel>
    <div style="margin-top:16px;">
        <a href="{{ route('parent.messages.index') }}" class="btn btn-outline">Back to Messages</a>
    </div>
@endsection
