@php
    /** @var \LaraBB\Category\Models\Category $category */
    /** @var \LaraBB\Forum\Models\Forum $forum */
    /** @var \LaraBB\Thread\Models\Thread $thread */
    /** @var \LaraBB\Post\Models\Post $post */
    $threadStyle = config('larabb.thread-style');
@endphp
@extends('layouts.master')
@section('content')
@include('partials.messages', ['autoHide' => 'auto-hide'])
<div class="d-flex justify-content-between align-items-center mb-3">
    <nav>

    </nav>
    {!! button('Create Posting')->permission($currentUser->forumPermissions[$forum->uuid]->getAttribute('create_posts'))
                                ->type('link')
                                ->href(route('reply', [$thread->slug]))
                                ->class('btn btn-purple text-uppercase')
                                ->icon('fas fa-fw fa-plus')
                                ->render() !!}
</div>
<div class="card mb-3 shadow-sm">
    @include('partials.breadcrumb', [
        'items' => [
            ['href' => 'index', 'parameters' => null, 'label' => null, 'icon' => 'home'],
            ['href' => 'category', 'parameters' => [$category->slug], 'label' => $category->title],
            ['href' => 'forum', 'parameters' => [$forum->slug], 'label' => $forum->title, 'mobile' => true],
            ['label' => $thread->prefix->display_style . ' ' . $thread->title, 'mobile' => true],
        ]
    ])
    <div class="card-body p-0">
    @foreach($posts as $post)
    <div class="row m-0" id="post-{{ $post->id }}"{!! !$loop->last && $threadStyle != 'classic' ? ' style="border-bottom:3px solid #dadada;"' : '' !!}>
        <div class="col-{{ $threadStyle == 'classic' ? 2 : 12 }} p-3 post-header {{ $threadStyle }}">
            <div class="d-flex justify-content-between align-items-start">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0 me-3">
                        <img src="https://dummyimage.com/60x60/efefef/000" class="rounded-circle border" alt="">
                    </div>
                    <div class="flex-grow-1">
                        <span style="color:{{ $post->createdBy->groups->where('priority', $post->createdBy->groups->max('priority'))->first()->color }}">{{ $post->createdBy->username }}</span>
                        <small class="d-block text-muted">
                            {{ $post->created_at->format($currentUser->profile->dateformat . ' - ' . $currentUser->profile->timeformat) }}
                        </small>
                    </div>
                </div>
                <small>
                    <a href="{{ route('thread', [$thread->slug]) }}#post-{{ $post->id }}">#{{ $post->id }}</a>
                </small>
            </div>
        </div>
        @if($threadStyle != 'classic')
        <hr style="border-top-width:2px;" class="m-0">
        @endif
        <div class="col-{{ $threadStyle == 'classic' ? 10 : 12 }} p-3 post-body {{ $threadStyle }}">
            <div class="content mb-3">
                {!! $post->content !!}
            </div>
        </div>
        <div class="col-12 post-footer {{ $threadStyle }}">
            <form action="{{ route('post-destroy') }}" method="post">
                @csrf
                <input type="hidden" name="uuid" value="{{ $post->uuid }}">
                <nav class="btn-group btn-group-sm">
                    @if($post->created_uuid === $currentUser->uuid || $currentUser->forumPermissions[$forum->uuid]->edit_posts)
                        <a href="{{ route('post-edit', [$post->uuid]) }}" class="btn btn-primary">
                            <span class="fas fa-fw fa-edit"></span> @lang('Edit')
                        </a>
                    @endif
                    @if($post->created_uuid === $currentUser->uuid || $currentUser->forumPermissions[$forum->uuid]->delete_posts)

                        <input type="hidden" name="uuid" value="{{ $post->uuid }}">
                        <button class="btn btn-sm btn-danger">
                            <span class="far fa-fw fa-trash-alt"></span> @lang('Delete')
                        </button>
                    @endif
                </nav>
            </form>
        </div>
    </div>
    @endforeach
    </div>
</div>
<div class="d-flex justify-content-between align-items-center mb-3">
    <nav>

    </nav>
    {!! button('Create Posting')->permission($currentUser->forumPermissions[$forum->uuid]->getAttribute('create_posts'))
                                ->type('link')
                                ->href(route('reply', [$thread->slug]))
                                ->class('btn btn-purple text-uppercase')
                                ->icon('fas fa-fw fa-plus')
                                ->render() !!}
</div>
@stop
