<section>
    <div class="bg-white dark:bg-neutral-800 shadow sm:rounded-lg sm:overflow-hidden">
        <div class="divide-y divide-gray-200 dark:divide-gray-400/40">
            <div class="px-4 py-5 sm:px-6">
                <h2 class="text-lg font-medium text-gray-900 dark:text-gray-200">Comments</h2>
            </div>
            <div>
                <!-- Comment Input -->
                <div class="bg-gray-50 dark:bg-neutral-800 px-4 py-6 sm:px-6">
                    @auth
                        <div class="flex">
                        <div class="flex-shrink-0 mr-4">
                            <img class="h-10 w-10 rounded-full" src="{{ auth()->user()->getAvatar() }}" alt="{{ auth()->user()->name }}">
                        </div>
                        <div class="min-w-0 flex-1">
                            <form wire:submit.prevent="postComment">
                                <div>
                                    <label for="comment" class="sr-only">Comment body</label>
                                    <textarea id="comment" name="comment" rows="3"
                                            class="peer block min-h-[auto] w-full border-1 bg-transparent px-3 py-[0.32rem] leading-[1.6] outline-none transition-all duration-200 ease-linear dark:placeholder:text-neutral-200 border-gray-300 dark:border-neutral-950 dark:bg-neutral-900 dark:text-gray-300 focus:border-rose-500 dark:focus:border-rose-600 focus:ring-rose-500 dark:focus:ring-rose-600 rounded-md shadow-sm
                                                @error('newCommentState.body') border-red-500 @enderror"
                                            placeholder="Write something" wire:model.defer="newCommentState.body"></textarea>
                                    @error('newCommentState.body')
                                        <p class="mt-2 text-sm text-red-500">{{ $message }}</p>
                                    @enderror
                                </div>
                                <div class="mt-3 flex items-center justify-between">
                                    <button type="submit"
                                            class="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-md shadow-sm text-white bg-rose-600 hover:bg-rose-700 focus:outline-none focus:ring-2 focus:ring-rose-500">
                                        Comment
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                    @endauth

                    @guest
                        <p class="text-gray-900 dark:text-gray-200">Log in to comment.</p>
                    @endguest
                </div>

                <!-- Comments -->
                <div class="px-4 py-6 sm:px-6">
                    <div class="space-y-8">
                        @if ($comments->isNotEmpty())
                            @foreach($comments as $comment)
                                <livewire:comment :comment="$comment" :key="$comment->id"/>
                            @endforeach
                            {{ $comments->links('pagination::tailwind') }}
                        @else
                            <p class="text-gray-900 dark:text-gray-200">No comments yet.</p>
                        @endif
                    </div>
                </div>
            </div>
        </div>

    </div>
</section>