@extends(Theme::viewName('layout'))
@section('title', trans('admin.edit_group_title', ['group_name' => $group->name]))

@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"><a href="{{ route('groups.index') }}">@lang('navigation.breadcrumb.groups')</a></li>
    <li class="breadcrumb-item active">@lang('navigation.breadcrumb.edit_group')</li>
@endsection

@section('content')
    <div class="container">
        <div class="row">
            <div class="col">
                <h1>@yield('title')</h1>
                <p>@lang('admin.edit_group_intro')</p>
                <hr/>

                <form action="{{ route('groups.update', [$group->id]) }}" method="post">
                    {{ csrf_field() }}
                    {{ method_field('PUT') }}
                    <div>
                        {{-- Nav tabs --}}
                        <ul class="nav nav-tabs" role="tablist">
                            @include(Theme::viewName('partials.tab'), ['active_tab' => 'details', 'tab_name' => 'details', 'tab_icon' => 'info-circle', 'tab_text' => trans('admin.group_details_tab')])
                            @include(Theme::viewName('partials.tab'), ['active_tab' => 'details', 'tab_name' => 'users', 'tab_icon' => 'users', 'tab_text' => trans('admin.group_users_tab')])
                            @include(Theme::viewName('partials.tab'), ['active_tab' => 'details', 'tab_name' => 'permissions', 'tab_icon' => 'lock', 'tab_text' => trans('admin.group_permissions_tab')])
                        </ul>

                        {{-- Tab panes --}}
                        <div class="tab-content">
                            {{-- Details --}}
                            <div role="tabpanel" class="tab-pane active" id="details-tab">
                                <div class="row">
                                    <div class="col-md-6 ml-md-auto mr-md-auto">
                                        <div class="form-group">
                                            <label class="form-control-label" for="group-name">@lang('forms.name_label')</label>
                                            <input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" id="group-name" name="name" value="{{ old('name') }}">

                                            @if ($errors->has('name'))
                                                <div class="invalid-feedback">
                                                    <strong>{{ $errors->first('name') }}</strong>
                                                </div>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>

                            {{-- Users --}}
                            <div role="tabpanel" class="tab-pane" id="users-tab">
                                @if ($group->users()->count() > 0)
                                    <p>@lang('admin.group_users_message', ['group_name' => $group->name])</p>
                                    <ul class="nav nav-pills">
                                        @foreach ($group->users as $user)
                                            <li class="nav-item"><a class="nav-link" href="{{ route('users.edit', [$user->id]) }}">{{ $user->name }}</a></li>
                                        @endforeach
                                    </ul>
                                @else
                                    <p class="text-danger">@lang('admin.group_no_users_message')</p>
                                    <div><a class="btn btn-secondary" href="{{ route('users.index') }}">@lang('admin.users_title')</a></div>
                                @endif
                            </div>

                            {{-- Permissions --}}
                            <div role="tabpanel" class="tab-pane" id="permissions-tab">
                                @php
                                    $callback = [$group, 'hasAdminPermission'];
                                    $callback_object = $group;
                                    $key_id = 'group_' . $group->id;
                                    $object_id = $group->id
                                @endphp

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'access')
                                ])

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'configure')
                                ])

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-albums')
                                ])

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-labels')
                                ])

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-comments')
                                ])

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-users')
                                ])

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-groups')
                                ])

                                @include(Theme::viewName('partials.permission_checkbox'), [
                                    'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-storage')
                                ])
                            </div>
                        </div>
                    </div>

                    <div class="text-right mt-3">
                        <a href="{{ route('groups.index') }}" class="btn btn-link">@lang('forms.cancel_action')</a>
                        <button class="btn btn-success" type="submit"><i class="fa fa-fw fa-check"></i> @lang('forms.save_action')</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection