@extends('layouts.app')

@section('content')
<div class="container-xxl flex-grow-1 container-p-y">
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Chat #{{ $chat->id }}</h5>
            <small class="text-muted">
                Course: {{ $chat->course?->title ?? 'No course' }}
                • Sender: {{ $chat->sender?->name }}
                • Receiver: {{ $chat->receiver?->name }}
            </small>
            <hr/>
        </div>

        <div class="card-body">
            <div class="p-3 border rounded" style="max-width: 900px;">
                <div class="d-flex justify-content-between">
                    <strong>{{ $chat->sender?->name }}</strong>
                    <small class="text-muted">{{ $chat->created_at?->format('Y-m-d H:i') }}</small>
                </div>
                <div class="mt-2">
                    {{ $chat->message }}
                </div>

                <div class="mt-3">
                    @if($chat->is_flagged)
                        <span class="badge bg-danger">Flagged</span>
                    @else
                        <span class="badge bg-secondary">Not flagged</span>
                    @endif
                </div>
            </div>

            <div class="mt-3 d-flex gap-2">
                <a href="{{ route('chats.index') }}" class="btn btn-secondary">Back</a>

                @can('chat flag')
                    <form method="POST" action="{{ route('chats.flag', $chat) }}">
                        @csrf
                        @method('PATCH')
                        <button class="btn btn-warning">{{ $chat->is_flagged ? 'Unflag' : 'Flag' }}</button>
                    </form>
                @endcan
            </div>
        </div>
    </div>
</div>
@endsection