@php use LaraBB\Category\Models\Category;use LaraBB\Forum\Models\Forum;use LaraBB\Group\Models\Group;use LaraBB\User\Models\User; @endphp
@php
    /** @var Category $category */
    /** @var Forum $forum */
    /** @var Group $group */
    /** @var User $user */
@endphp
@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, 'mobile' => true],
        ['label' => 'Create Thread', 'mobile' => true],
    ]"/>
    <form action="{{ route('thread-store') }}" method="post">
        @csrf
        <x-atomic.input-hidden name="forum_uuid" :value="$forum->uuid" />
        <div class="card-body">
            @include('partials.messages')
            <div class="row">
                <div class="col-12 col-lg-3">
                    <x-atomic.input-select name="prefix"
                                           label="Prefix"
                                           :options="$forum->prefixes"
                                           keyForValue="uuid"
                                           keyForText="prefix"
                                           value="{{ $prefix->uuid ?? '' }}"
                                           selectpicker
                                           maxOptions="1"
                                           liveSearch />
                </div>
                <div class="col-12 col-lg-9 mb-3">
                    <x-atomic.input-text name="title" label="Title" value="{{ $thread->title ?? '' }}" required />
                </div>
            </div>
            <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', $thread->firstPost->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="$thread->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"
                                           :value="$thread->users ?? []"
                                           multiple
                                           selectpicker
                                           maxOptions="{{ $users->count() }}"
                                           liveSearch />
                </div>
            </div>
        </div>
        <div class="card-footer d-grid">
            <button class="btn btn-purple btn-lg">
                <span class="fas fa-fw fa-save"></span> @lang('Create Thread')
            </button>
        </div>
    </form>
</x-atomic.card>
@stop
@section('pagejs')
    <script src="{{ asset('js/bootstrap-select.min.js') }}"></script>
@stop
