@extends('layouts.master')
@section('pagecss')
    <link rel="stylesheet" type="text/css" href="{{ asset('css/bootstrap-select.min.css') }}">
@stop
@section('content')
<x-atomic.card>
    <x-molecule.breadcrumb :items="[
        [
            'href' => 'index',
            'parameters' => null,
            'label' => null,
            'icon' => 'home'
        ],
        [
            'href' => 'category',
            'parameters' => [$forum->category->slug],
            'label' => $forum->category->title
        ],
        [
            'href' => 'forum',
            'parameters' => [$forum->slug],
            'label' => $forum->title
        ],
        [
            'href' => 'thread',
            'parameters' => [isset($post) ? $post->thread->slug : $thread->slug],
            'label' => (isset($post) ? $post->thread->title : $thread->title),
            'mobile' => true
        ],
        [
            'label'  => ($edit ? 'Edit ' : 'Create ') . 'Posting',
            'mobile' => true
        ]
    ]" />
    <form action="{{ route('post-' . ($edit ? 'update' : 'store')) }}" method="post">
        @csrf
        <input type="hidden" name="thread_uuid" value="{{ $thread->uuid ?? '' }}">
        @if($edit)
        <input type="hidden" name="uuid" value="{{ $post->uuid }}">
        @endif
        <div class="card-body">
            @include('partials.messages')
            @if(isset($post) && $post->thread->firstpost_uuid === $post->uuid)
            <div class="row mb-3">
                <div class="col-12 col-lg-3">
                    <x-atomic.input-select name="prefix"
                                           label="Prefix"
                                           :options="$forum->prefixes"
                                           keyForValue="uuid"
                                           keyForText="prefix"
                                           value="{{ $post->thread->prefix_uuid ?? $thread->prefix_uuid }}"
                                           required
                                           selectpicker
                                           maxOptions="1"
                                           liveSearch />
                </div>
                <div class="col-12 col-lg-9">
                    <x-atomic.input-text name="title" label="Title" value="{{ $post->title ?? 'RE: ' . $thread->title }}" required />
                </div>
            </div>
            @else
            <div class="col-12">
                <x-atomic.input-text name="title" label="Title" value="{{ $post->title ?? 'RE: ' . $thread->title }}" required />
            </div>
            @endif
            <div class="col-12 mb-3">
                <label for="content" class="form-label required">@lang('Content'):</label>
                <textarea class="form-control @error('content')is-invalid @enderror" id="content" name="content"
                          rows="8">{{ old('content', $edit ? $post->content : '') }}</textarea>
            </div>
            <div class="row mb-3">
                <div class="col-12 col-lg-3">
                    <x-atomic.input-select name="groups"
                                           label="Only visible above this group"
                                           :options="$groups"
                                           keyForValue="uuid"
                                           keyForText="group"
                                           :values="$post->groups ?? []"
                                           multiple
                                           selectpicker
                                           maxOptions="1"
                                           liveSearch />
                </div>
                <div class="col-12 col-lg-9">
                    <x-atomic.input-select name="users"
                                           label="Only visible for these users"
                                           :options="$users"
                                           keyForValue="uuid"
                                           keyForText="username"
                                           :values="$post->users ?? []"
                                           multiple
                                           selectpicker
                                           maxOptions="{{ $users->count() }}"
                                           liveSearch />
                </div>
            </div>
        </div>
        <div class="card-footer d-grid">
            <button class="btn btn-primary btn-lg">
                <span class="fas fa-fw fa-save"></span> @lang(($edit ? 'Edit ' : 'Create ') . 'Posting')
            </button>
        </div>
    </form>
</x-atomic.card>
@stop
@section('pagejs')
    <script src="{{ asset('js/bootstrap-select.min.js') }}"></script>
@stop
