<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>
<div class="page-header"><div><h1><i class="bi bi-person-badge me-2 text-primary"></i><?= esc($emp['name']??'Employee') ?></h1><nav aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="<?= base_url('employees') ?>">Workforce</a></li><li class="breadcrumb-item active"><?= esc($emp['emp_code']) ?></li></ol></nav></div>
<a href="<?= base_url('employees/edit/'.$emp['id']) ?>" class="btn btn-fm-outline btn-sm">Edit</a></div>
<div class="row g-3">
<div class="col-lg-4">
<div class="fm-form-section text-center"><div class="user-avatar mx-auto mb-3" style="width:64px;height:64px;font-size:1.5rem"><?= strtoupper(substr($emp['name']??'?',0,2)) ?></div>
<h5 class="fw-bold"><?= esc($emp['name']??'N/A') ?></h5>
<div class="small text-muted mb-1"><?= esc($emp['designation']) ?></div>
<div class="small text-muted mb-3"><?= esc($emp['department']) ?></div>
<span class="fm-badge badge-status-<?= esc($emp['status']) ?>"><?= ucfirst(str_replace('_',' ',$emp['status'])) ?></span>
<hr><div class="text-start small">
<div class="mb-2"><span class="text-muted">Employee Code:</span> <strong><?= esc($emp['emp_code']) ?></strong></div>
<div class="mb-2"><span class="text-muted">Facility:</span> <?= esc($emp['facility_name']??'—') ?></div>
<div class="mb-2"><span class="text-muted">Email:</span> <?= esc($emp['email']??'—') ?></div>
<div class="mb-2"><span class="text-muted">Phone:</span> <?= esc($emp['phone']??'—') ?></div>
<div class="mb-2"><span class="text-muted">Shift:</span> <?= substr($emp['shift_start'],0,5) ?> – <?= substr($emp['shift_end'],0,5) ?></div>
<div class="mb-2"><span class="text-muted">Hourly Rate:</span> <?= $currency ?> <?= number_format($emp['hourly_rate'],2) ?></div>
<div><span class="text-muted">Hire Date:</span> <?= $emp['hire_date'] ? date('d M Y',strtotime($emp['hire_date'])) : '—' ?></div>
</div></div>
</div>
<div class="col-lg-8">
<div class="fm-card mb-3"><div class="card-header-fm"><h5><i class="bi bi-calendar-check"></i>Recent Attendance</h5></div>
<div class="fm-card-body p-0"><table class="fm-table"><thead><tr><th>Date</th><th>Check In</th><th>Check Out</th><th>Status</th></tr></thead><tbody>
<?php foreach(array_slice($attendance,0,10) as $a): ?><tr><td class="small"><?= date('d M Y',strtotime($a['date'])) ?></td><td class="small"><?= $a['check_in'] ? date('H:i',strtotime($a['check_in'])) : '—' ?></td><td class="small"><?= $a['check_out'] ? date('H:i',strtotime($a['check_out'])) : '—' ?></td><td><span class="fm-badge badge-status-<?= esc($a['status']) ?>"><?= ucfirst($a['status']) ?></span></td></tr><?php endforeach; ?>
<?php if(empty($attendance)): ?><tr><td colspan="4" class="text-center py-3 text-muted">No attendance records</td></tr><?php endif; ?>
</tbody></table></div></div>
<div class="fm-card"><div class="card-header-fm"><h5><i class="bi bi-tools"></i>Assigned Work Orders</h5></div>
<div class="fm-card-body p-0"><table class="fm-table"><thead><tr><th>WO #</th><th>Title</th><th>Priority</th><th>Status</th></tr></thead><tbody>
<?php foreach($assignedWO as $w): ?><tr><td><a href="<?= base_url('workorders/view/'.$w['id']) ?>" class="text-primary"><?= esc($w['wo_number']) ?></a></td><td class="small"><?= esc(substr($w['title'],0,35)) ?></td><td><span class="fm-badge badge-priority-<?= esc($w['priority']) ?>"><?= ucfirst($w['priority']) ?></span></td><td><span class="fm-badge badge-status-<?= esc($w['status']) ?>"><?= ucfirst(str_replace('_',' ',$w['status'])) ?></span></td></tr><?php endforeach; ?>
<?php if(empty($assignedWO)): ?><tr><td colspan="4" class="text-center py-3 text-muted">No work orders assigned</td></tr><?php endif; ?>
</tbody></table></div></div>
</div></div>
<?= $this->endSection() ?>
