@extends('admin.layouts.app')
@section('panel')
    <div class="row">

        <div class="col-lg-12">
            <div class="show-filter mb-3 text-end">
                <button type="button" class="btn btn-outline--primary showFilterBtn btn-sm"><i class="las la-filter"></i>
                    @lang('Filter')</button>
            </div>
            <div class="card responsive-filter-card mb-4">
                <div class="card-body">
                    <form action="">
                        <div class="d-flex flex-wrap gap-4">
                            <div class="flex-grow-1">
                                <label>@lang('Name')</label>
                                <input type="text" name="search" value="{{ request()->search }}" class="form-control">
                            </div>

                            <div class="flex-grow-1">
                                <label>@lang('Date')</label>
                                <input name="date" type="text" data-range="true" data-multiple-dates-separator=" - "
                                    data-language="en" class="datepicker-here form-control" data-position='bottom right'
                                    placeholder="@lang('Start date - End date')" autocomplete="off" value="{{ request()->date }}">
                            </div>

                            <div class="flex-grow-1 align-self-end">
                                <button class="btn btn--primary w-100 h-45"><i class="fas fa-filter"></i>
                                    @lang('Filter')</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>



            <div class="card b-radius--10 ">
                <div class="card-body p-0">
                    <div class="table-responsive--md  table-responsive">
                        <table class="table table--light style--two">
                            <thead>
                                <tr>
                                    <th>@lang('Role')</th>
                                    <th>@lang('created at')</th>
                                    <th>@lang('User Count')</th>
                                    <th>@lang('Permissions')</th>
                                    <th>@lang('Action')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($roles as $role)
                                    <tr>
                                        <td>
                                            <span class="fw-bold">{{ $role->name }}</span>
                                            <br>
                                            <span class="small">{{ $role->guard_name }}</span>
                                        </td>

                                        <td>
                                            {{ $role->created_at->format('d M, Y') }} <br>
                                            {{ diffForHumans($role->created_at) }}
                                        </td>
                                        <td>
                                            <span class="fw-bold">{{ $role->users_count ?? 0 }}</span>
                                        </td>

                                        <td>
                                            @foreach ($role->permissions as $permission)
                                                <span class="badge badge--primary fw-bold">{{ str($permission->name)->headline() }}</span>
                                            @endforeach
                                        </td>
                                        <td>
                                            <button data-action="{{ route('admin.access.roles.create-edit', $role->id) }}"
                                                data-title="@lang('Edit Role : ') {{ $role->name }}"
                                                data-success="initialiseSelect2"
                                                class="btn btn-sm btn-outline--primary formModalBtn">
                                                <i class="las la-desktop text--shadow"></i> @lang('Edit')
                                            </button>

                                        </td>

                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%">{{ __($emptyMessage) }}</td>
                                    </tr>
                                @endforelse

                            </tbody>
                        </table><!-- table end -->
                    </div>
                </div>
                @if ($roles->hasPages())
                    <div class="card-footer py-4">
                        {{ paginateLinks($roles) }}
                    </div>
                @endif
            </div>
        </div>

        <x-form-modal />
    </div>
@endsection



@push('breadcrumb-plugins')
    <button data-action="{{ route('admin.access.roles.create-edit') }}" data-title="@lang('Create Role')"
        class="btn btn-sm btn-outline--primary formModalBtn"><i class="fas fa-plus"></i> Add
        Role</button>
@endpush

@push('style-lib')
    <link rel="stylesheet" href="{{ asset('assets/admin/css/vendor/datepicker.min.css') }}">
@endpush


@push('script-lib')
    <script src="{{ asset('assets/admin/js/vendor/datepicker.min.js') }}"></script>
    <script src="{{ asset('assets/admin/js/vendor/datepicker.en.js') }}"></script>
@endpush
