{{-- ── Header del usuario ───────────────────────────────────────────── --}}
{{-- Izquierda: avatar + datos --}}
{{-- Avatar --}}
{{ strtoupper(substr($user->first_name ?: $user->name, 0, 1)) }}{{ strtoupper(substr($user->last_name ?: '', 0, 1)) }}
{{-- Nombre + datos de contacto --}}

@if($user->title) {{ $user->title }} @endif {{ $user->first_name && $user->last_name ? $user->first_name . ' ' . $user->last_name : $user->name }}

{{-- Empresa --}} @if($user->company)
@if($user->company->logo_path && \Illuminate\Support\Facades\Storage::disk('public')->exists($user->company->logo_path)) @else @endif {{ $user->company->apodo ?: $user->company->name }}
@endif {{-- Contacto inline --}}
@if($user->email) {{ $user->email }} @endif @if($user->phone) {{ $user->phone }} @endif @if($user->address) {{ $user->address }} @endif
{{-- Derecha: estado + validez + botones --}}
{{-- Estado --}} @php $statusBadge = match($user->status ?? 'active') { 'active' => ['badge-success', 'Activo'], 'inactive' => ['badge-ghost', 'Inactivo'], 'suspended' => ['badge-error', 'Suspendido'], default => ['badge-ghost', ucfirst($user->status ?? '')], }; @endphp {{ $statusBadge[1] }} {{-- Rol principal --}} @foreach($user->roles->take(1) as $role) {{ $role->name }} @endforeach
{{-- Validez --}} @if($user->valid_from || $user->valid_until) @php $now = now(); $from = $user->valid_from; $until = $user->valid_until; $isExpired = $until && $until->lt($now); $expireSoon = !$isExpired && $until && $until->diffInDays($now) <= 30; $notStarted = $from && $from->gt($now); $validColor = $isExpired || $notStarted ? 'text-error' : ($expireSoon ? 'text-warning' : 'text-gray-400'); @endphp

@if($from && $until) {{ $from->format('d/m/Y') }} → {{ $until->format('d/m/Y') }} @elseif($from) Desde {{ $from->format('d/m/Y') }} @else Hasta {{ $until->format('d/m/Y') }} @endif @if($isExpired) (Expirado) @elseif($notStarted) (No activo aún) @elseif($expireSoon) (Expira pronto) @endif

@endif {{-- Botones --}}
{{-- ── Tabs ──────────────────────────────────────────────────────────────── --}}
{{-- ════════════════════════════════════════════════════════════════════ TAB: FICHA ════════════════════════════════════════════════════════════════════ --}} @if($activeTab === 'ficha')
{{-- Información básica --}}

Información básica

Nombre {{ trim(($user->title ? $user->title.' ' : '').($user->first_name ?? '').' '.($user->last_name ?? '')) ?: $user->name }}
Usuario {{ $user->name }}
Email {{ $user->email }}
Teléfono {{ $user->phone ?: '—' }}
Dirección {{ $user->address ?: '—' }}
Miembro desde {{ $user->created_at?->format('d/m/Y') ?? '—' }}
{{-- Validez y estado --}}

Validez de acceso

Estado {{ $statusBadge[1] }}
Válido desde {{ $user->valid_from ? $user->valid_from->format('d/m/Y') : '— (sin límite)' }}
Válido hasta {{ $user->valid_until ? $user->valid_until->format('d/m/Y') : '— (sin límite)' }}
Email verificado @if($user->email_verified_at) {{ $user->email_verified_at->format('d/m/Y') }} @else Pendiente @endif
{{-- Empresa --}} @if($user->company)

Empresa

@if($user->company->logo_path && \Illuminate\Support\Facades\Storage::disk('public')->exists($user->company->logo_path)) @else
@endif

{{ $user->company->name }}

@if($user->company->apodo)

{{ $user->company->apodo }}

@endif @if($user->company->email)

{{ $user->company->email }}

@endif
@php $typeBadge = match($user->company->type) { 'owner' => ['badge-success', 'Promotor'], 'constructor' => ['badge-primary', 'Constructor'], 'subcontractor' => ['badge-secondary','Subcontratista'], 'consultant' => ['badge-info', 'Consultor'], 'supplier' => ['badge-warning', 'Proveedor'], default => ['badge-ghost', 'Otro'], }; @endphp {{ $typeBadge[1] }}
@endif
@endif {{-- ════════════════════════════════════════════════════════════════════ TAB: PERMISOS ════════════════════════════════════════════════════════════════════ --}} @if($activeTab === 'permissions')
{{-- Roles --}}

Roles asignados

@if($user->roles->isEmpty())

Sin roles asignados.

@else
@foreach($user->roles as $role)
{{ $role->name }}
@endforeach
@endif
{{-- Permisos directos del usuario --}}

Permisos

Los permisos heredados de un rol aparecen marcados y bloqueados. Aquí puedes conceder permisos extra directamente a este usuario.

@forelse($grouped as $section => $perms)
@foreach($perms as $perm) @php $viaRole = in_array($perm->name, $rolePerms, true); $direct = in_array($perm->name, $directPerms, true); @endphp @endforeach
@empty

{{ __('No permissions') }}

@endforelse
@endif {{-- ════════════════════════════════════════════════════════════════════ TAB: PROYECTOS ════════════════════════════════════════════════════════════════════ --}} @if($activeTab === 'projects')
{{-- Formulario asignar --}}

Asignar proyecto

@if($availableProjects->isEmpty())

El usuario ya está asignado a todos los proyectos disponibles.

@else
@error('addProjectId')

{{ $message }}

@enderror
@endif
{{-- Lista proyectos --}} @if($user->projects->isEmpty())

Sin proyectos asignados.

@else
@foreach($user->projects as $project) @php $avg = $project->phases->avg('progress_percent') ?? 0; $sCfg = match($project->status) { 'in_progress' => ['badge-primary', 'En progreso'], 'completed' => ['badge-success', 'Completado'], 'paused' => ['badge-warning', 'Pausado'], 'planning' => ['badge-ghost', 'Planificación'], default => ['badge-ghost', ucfirst($project->status)], }; @endphp @endforeach
Proyecto Rol Estado Progreso
{{ $project->name }} @if($project->address)

{{ $project->address }}

@endif
{{ $project->pivot->role_in_project ?? '—' }} {{ $sCfg[1] }}
{{ round($avg) }}%
@endif
@endif {{-- ════════════════════════════════════════════════════════════════════ TAB: ACTIVIDAD ════════════════════════════════════════════════════════════════════ --}} @if($activeTab === 'activity')
{{-- Inspecciones --}}

Últimas inspecciones

@if($recentInspections->isEmpty())

Sin inspecciones registradas

@else
@foreach($recentInspections as $ins) @php $rCfg = match($ins->result ?? '') { 'pass' => ['badge-success', 'OK'], 'fail' => ['badge-error', 'Fallo'], default => ['badge-ghost', '—'], }; @endphp
{{ $ins->template?->name ?? 'Inspección' }} {{ $rCfg[1] }}
@if($ins->feature?->layer?->phase?->project) {{ $ins->feature->layer->phase->project->name }} @endif {{ $ins->created_at->diffForHumans() }}
@endforeach
@endif
{{-- Issues reportados --}}

Issues reportados

@if($recentIssues->isEmpty())

Sin issues reportados

@else
@foreach($recentIssues as $issue) @php $pCfg = match($issue->priority ?? 'medium') { 'critical' => ['badge-error', 'Crítico'], 'high' => ['badge-warning', 'Alto'], 'medium' => ['badge-info', 'Medio'], default => ['badge-ghost', 'Bajo'], }; $stCfg = match($issue->status ?? 'open') { 'open' => 'text-orange-500', 'closed' => 'text-green-500', default => 'text-gray-400', }; @endphp
{{ $issue->title }} {{ $pCfg[1] }}
@if($issue->project) {{ $issue->project->name }} @endif {{ ucfirst($issue->status ?? 'open') }}
@endforeach
@endif
@endif {{-- ════════════════════════════════════════════════════════════════════ TAB: NOTAS ════════════════════════════════════════════════════════════════════ --}} @if($activeTab === 'notes')

Notas internas

@if(!$editingNotes) @endif
@if($editingNotes)
@else @if($user->notes)
{{ $user->notes }}
@else

Sin notas.

@endif @endif
@endif