@extends(Theme::viewName('layout'))
@section('title', trans('admin.list_groups_title'))

@section('breadcrumb')
    <li class="breadcrumb-item"><a href="{{ route('home') }}"><i class="fa fa-fw fa-home"></i></a></li>
    <li class="breadcrumb-item"><a href="{{ route('admin') }}">@lang('navigation.breadcrumb.admin')</a></li>
    <li class="breadcrumb-item active">@lang('navigation.breadcrumb.groups')</li>
@endsection

@section('content')
    <div class="container">
        <div class="row">
            <div class="col">
                <h1>@yield('title')</h1>
                <div class="alert alert-info" style="margin-bottom: 30px;">
                    <i class="fa fa-fw fa-info"></i> @lang('admin.list_groups_intro')
                </div>

                @if (count($groups) == 0)
                    <div class="text-center">
                        <h4 class="text-danger"><b>@lang('admin.no_groups_title')</b></h4>
                        <p>@lang('admin.no_groups_text')</p>
                        <p style="margin-top: 40px;">
                            <a href="{{ route('groups.create') }}" class="btn btn-lg btn-success">@lang('admin.create_group')</a>
                        </p>
                    </div>
                @else
                    <table class="table table-hover table-striped">
                        <tbody>
                        @foreach ($groups as $group)
                            <tr>
                                <td>
                                    <a href="{{ route('groups.edit', ['id' => $group->id]) }}"><span style="font-size: 1.3em;">{{ $group->name }}</span></a><br/>
                                    <span class="{{ $group->users()->count() == 0 ? "text-danger" : "text-success" }}">{{ trans_choice('admin.group_number_users', $group->users()->count()) }}</span>
                                </td>
                                <td class="text-right">
                                    <a href="{{ route('groups.delete', ['id' => $group->id]) }}" class="btn btn-danger">@lang('forms.delete_action')</a>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>

                    <div class="text-center">
                        {{ $groups->links() }}
                    </div>

                    <div class="pull-right" style="margin-top: 10px;">
                        @can('admin:manage-users')
                            <a href="{{ route('users.index') }}" class="btn btn-link">@lang('admin.list_users_title')</a>
                        @endcan
                        <a href="{{ route('groups.create') }}" class="btn btn-success"><i class="fa fa-fw fa-plus"></i> @lang('admin.create_group')</a>
                    </div>
                @endif
            </div>
        </div>
    </div>
@endsection