@extends('layouts.admin.layout') @php /* * Map permission sets to human-readable role labels. * Ordered from most specific to most generic so the first match wins. */ $rolePresets = [ 'Full Access' => '__all__', 'Preacher' => ['create-sermons','read-sermons','update-sermons','delete-sermons'], 'Event Coordinator' => ['create-events','read-events','update-events','create-gallery','read-gallery','update-gallery'], 'Finance Officer' => ['create-funds','read-funds','update-funds','view-funds','read-payments','create-payments','read-reports','view-reports'], 'Content Manager' => ['create-bulletins','read-bulletins','view-bulletins','create-quotes','read-quotes','update-quotes','create-gallery','read-gallery','update-gallery','create-files','read-files','view-files'], 'Prayer Coordinator' => ['read-prayers','update-prayers'], 'Support Coordinator' => ['read-helps','update-helps'], 'Web Admin' => ['read-contacts','read-feedbacks','update-feedbacks'], 'Email Blaster Manager' => ['manage-email-blaster'], 'CMS Manager' => ['manage-cms'], 'Attendance Coordinator' => ['read-attendance','create-attendance','update-attendance'], ]; $allPermissionNames = App\Models\Permission::pluck('name')->sort()->values()->toArray(); function detectRole(array $userPerms, array $presets, array $allPerms): string { if (empty($userPerms)) return ''; sort($userPerms); $sortedAll = $allPerms; sort($sortedAll); if ($userPerms === $sortedAll) return 'Full Access'; foreach ($presets as $label => $required) { if ($required === '__all__') continue; sort($required); if ($userPerms === $required) return $label; } return 'Custom'; } @endphp @section('content')
{{-- Header --}}

Sub Admins ({{ $subadmins->count() }})

Add Sub Admin
@include('partials.message') {{-- Search --}}
@if($search) Clear @endif
{{-- Table --}}
{{-- Sub Admin --}} {{-- Contact --}} {{-- Last Login --}} {{-- Role --}} {{-- Permissions --}} {{-- Actions --}} @forelse($subadmins as $subadmin) @php $profile = $subadmin->userprofile; $fullname = $profile ? trim($profile->firstname . ' ' . $profile->lastname) : $subadmin->name; $avatar = $profile?->AvatarPath; $userPerms = $subadmin->permissions->pluck('name')->sort()->values()->toArray(); $roleLabel = detectRole($userPerms, $rolePresets, $allPermissionNames); @endphp {{-- Avatar + Name --}} {{-- Contact --}} {{-- Last Login --}} {{-- Role label --}} {{-- Permissions --}} {{-- Actions --}} @empty @endforelse
Sub Admin Contact Last Login Role Permissions Actions
@if($avatar) @else
{{ strtoupper(substr($fullname, 0, 1)) }}
@endif

{{ $fullname }}

{{ $subadmin->name }}

@if($subadmin->email)

{{ $subadmin->email }}

@endif @if($subadmin->mobile_no)

{{ $subadmin->mobile_no }}

@endif @if(!$subadmin->email && !$subadmin->mobile_no) @endif
@if($subadmin->last_login_at) @php $loginAt = \Carbon\Carbon::parse($subadmin->last_login_at); @endphp

{{ $loginAt->format('d M Y') }}

{{ $loginAt->format('g:i A') }}

@else Never @endif
@if($roleLabel === 'Full Access') Full Access @elseif($roleLabel === 'Custom') Custom @elseif($roleLabel) {{ $roleLabel }} @else @endif @if(count($userPerms)) @else @endif

@if($search) No sub admins found matching "{{ $search }}". @else No sub admins yet. Add the first one. @endif

@endsection @push('scripts') @endpush