@extends('layouts.app')
@section('title','Employees')
@section('content')
<div class="page-header"><div class="page-header-left"><div class="page-header-title"><h5>Employees</h5></div></div><div class="page-header-right ms-auto">@can('create_employees')<a href="{{ route('employees.create') }}" class="btn btn-primary"><i class="feather-user-plus me-1"></i>Create Employee</a>@endcan</div></div>
<div class="main-content" data-testid="employees-professional-ui"><div class="row g-3 mb-4">@foreach([['Total Employees',$summary['total'],'primary'],['Active Employees',$summary['active'],'success'],['Departments Covered',$summary['departments'],'warning']] as [$label,$value,$class])<div class="col-md-4"><div class="card border h-100"><div class="card-body"><small class="text-muted fw-semibold">{{ $label }}</small><div class="fs-3 fw-bold text-{{ $class }} mt-1">{{ $value }}</div></div></div></div>@endforeach</div>
<div class="card border overflow-hidden"><form method="GET" class="row g-2 p-3 border-bottom"><div class="col-lg-4"><div class="input-group"><span class="input-group-text"><i class="feather-search"></i></span><input name="q" value="{{ request('q') }}" class="form-control" placeholder="Search Employee, email, code or title"></div></div><div class="col-lg-3"><select name="department_id" class="form-select"><option value="">All Departments</option>@foreach($departments as $department)<option value="{{ $department->id }}" @selected((int)request('department_id')===$department->id)>{{ $department->name }}</option>@endforeach</select></div><div class="col-lg-2"><select name="employment_type" class="form-select"><option value="">All types</option>@foreach(['full_time'=>'Full Time','part_time'=>'Part Time','contract'=>'Contract','intern'=>'Intern'] as $v=>$l)<option value="{{ $v }}" @selected(request('employment_type')===$v)>{{ $l }}</option>@endforeach</select></div><div class="col-lg-2"><select name="status" class="form-select"><option value="">All statuses</option>@foreach(['active'=>'Active','inactive'=>'Inactive','on_leave'=>'On Leave','terminated'=>'Terminated'] as $v=>$l)<option value="{{ $v }}" @selected(request('status')===$v)>{{ $l }}</option>@endforeach</select></div><div class="col-lg-1 d-flex gap-1"><button class="btn btn-primary"><i class="feather-filter"></i></button><a href="{{ route('employees.index') }}" class="btn btn-light"><i class="feather-refresh-cw"></i></a></div></form>
<div class="table-responsive"><table class="table table-hover mb-0"><thead class="bg-light"><tr><th class="p-3">Employee & User Details</th><th>Department</th><th>Manager</th><th>Employment</th><th>Status</th><th class="text-end pe-3">Actions</th></tr></thead><tbody>@forelse($employees as $employee)<tr><td class="p-3"><div class="d-flex align-items-center gap-3"><span class="avatar-text avatar-md bg-soft-primary text-primary">{{ strtoupper(substr($employee->user?->name??'E',0,1)) }}</span><div><strong>{{ $employee->user?->name ?: 'Deleted User' }}</strong><span class="badge bg-soft-secondary text-secondary ms-1">{{ $employee->employee_code }}</span><small class="d-block text-muted">{{ $employee->user?->email }}{{ $employee->job_title?' · '.$employee->job_title:'' }}</small>@if($employee->user?->teams->isNotEmpty())<small class="text-primary">Team: {{ $employee->user->teams->pluck('name')->join(', ') }}</small>@endif</div></div></td><td>{{ $employee->department?->name ?: 'Not assigned' }}</td><td>{{ $employee->manager?->user?->name ?: 'Not assigned' }}</td><td><span class="badge bg-soft-info text-info">{{ ucwords(str_replace('_',' ',$employee->employment_type)) }}</span>@if($employee->hire_date)<small class="d-block text-muted mt-1">Since {{ $employee->hire_date->format('d M Y') }}</small>@endif</td><td><span class="badge {{ $employee->status==='active'?'bg-soft-success text-success':($employee->status==='terminated'?'bg-soft-danger text-danger':'bg-soft-warning text-warning') }}">{{ ucwords(str_replace('_',' ',$employee->status)) }}</span></td><td><div class="hstack gap-2 justify-content-end pe-2">@can('update_employees')<a href="{{ route('employees.edit',$employee) }}" class="avatar-text avatar-md bg-soft-warning text-warning"><i class="feather-edit-3"></i></a>@endcan @can('delete_employees')<form method="POST" action="{{ route('employees.destroy',$employee) }}" onsubmit="return confirm('Delete this Employee record? The User account will remain.')">@csrf @method('DELETE')<button class="avatar-text avatar-md border-0 bg-soft-danger text-danger"><i class="feather-trash-2"></i></button></form>@endcan</div></td></tr>@empty<tr><td colspan="6" class="text-center text-muted py-5">No Employees found.</td></tr>@endforelse</tbody></table></div><div class="p-3 border-top">{{ $employees->links() }}</div></div></div>
@endsection
