<x-app-layout title="{{ $channel->name }}">
    <div class="mx-auto flex max-w-2xl flex-col" style="height: calc(100vh - 8rem);">
        <div class="shrink-0 border-b border-slate-200 pb-4">
            <h1 class="text-xl font-semibold text-slate-900"># {{ $channel->name }}</h1>
            @if ($channel->description)
                <p class="mt-1 text-sm text-slate-600">{{ $channel->description }}</p>
            @endif
        </div>

        <div class="flex-1 space-y-4 overflow-y-auto py-4">
            @foreach ($messages as $message)
                <div class="rounded-xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
                    <p class="text-sm font-medium text-slate-900">{{ $message->sender_name }}</p>
                    <p class="mt-1 text-sm text-slate-700 whitespace-pre-wrap">{{ $message->body }}</p>
                    @if ($message->replies->isNotEmpty())
                        <div class="mt-3 space-y-2 border-l-2 border-slate-100 pl-3">
                            @foreach ($message->replies as $reply)
                                <div>
                                    <p class="text-xs font-medium text-slate-600">{{ $reply->sender_name }}</p>
                                    <p class="text-sm text-slate-700">{{ $reply->body }}</p>
                                </div>
                            @endforeach
                        </div>
                    @endif
                </div>
            @endforeach
            {{ $messages->links() }}
        </div>

        <form method="POST" action="{{ route('meet.channels.messages.store', $channel) }}" class="shrink-0 border-t border-slate-200 pt-4">
            @csrf
            <div class="flex gap-2">
                <input type="text" name="body" required placeholder="Message #{{ $channel->name }}" class="flex-1 rounded-lg border-slate-300 text-sm">
                <button type="submit" class="btn-primary">Send</button>
            </div>
        </form>
    </div>
</x-app-layout>
