@php /** @var LaraBB\User\Models\User $user */ @endphp
@extends('admin::Layouts.master')
@section('content')
    <div class="container-fluid pt-4">
        @include('partials.messages')
        <div class="row">
            <div class="col-12 col-sm-6">
                @include('partials.button', ['context' => 'primary', 'href' => 'admin.users.create', 'parameters' => [], 'icon' => 'plus', 'label' => 'Neuen Benutzer erstellen'])
            </div>
            <div class="col-12 offset-sm-4 col-sm-2">
                <div class="input-group">
                    <span class="input-group-text"><span class="fas fa-search"></span></span>
                    <input class="form-control search" placeholder="Suche...">
                </div>
            </div>
        </div>
        <div class="d-none d-lg-flex mt-4 py-2">
            <div class="col-12 col-lg-5 font-weight-bolder">Benutzername</div>
            <div class="col-12 col-lg-2 font-weight-bolder">E-Mail Adresse</div>
            <div class="col-12 col-lg-2 font-weight-bolder text-center">Gruppen</div>
            <div class="col-12 col-lg-2 font-weight-bolder text-center">Registriert</div>
        </div>
        @forelse($users as $user)
        <div class="d-flex hover align-items-center{{ $loop->last ? ' mb-3' : '' }}">
            <div class="col-12 col-lg-5">
                <a href="{{ route('admin.users.edit', [$user->uuid]) }}" class="d-block">
                    {{ $user->username }}
                </a>
            </div>
            <div class="col-12 col-lg-2">
                {{ $user->email_encrypted }}
            </div>
            <div class="col-12 col-lg-2 text-lg-center d-flex flex-wrap justify-content-{{ count($user->groups) > 3 ? 'between' : (count($user->groups) > 1 ? 'around' : 'center') }}">
                @foreach($user->groups as $group)
                <div class="small d-flex align-items-center">
                    <span class="badge badge-pill" style="background:{{ $group->color }}">&nbsp;</span>&nbsp;{{ $group->group }}
                </div>
                @endforeach
            </div>
            <div class="col-12 col-lg-2 text-lg-center">
                {{ $user->created_at->format('d.m.Y - H:i \U\h\r') }}
            </div>
            <div class="col-12 col-lg-1 text-lg-end">
                <form action="{{ route('admin.users.destroy') }}" enctype="multipart/form-data" method="post" class="delete" data-message="Wollen Sie diesen Benutzer wirklich löschen?">
                    @csrf
                    <input type="hidden" name="uuid" value="{{ $user->uuid }}">
                    <button class="btn">
                        <span class="far fa-trash-alt"></span>
                    </button>
                </form>
            </div>
        </div>
        @if(!$loop->last) <hr class="my-0"> @endif
        @empty
        <div class="row mb-3">
            <div class="col-12 text-center">
                Es sind keine Benutzer in der Datenbank vorhanden.
            </div>
        </div>
        @endforelse
        @include('partials.button', ['context' => 'primary', 'href' => 'admin.users.create', 'parameters' => [], 'icon' => 'plus', 'label' => 'Neuen Benutzer erstellen'])
    </div>
@stop
