@extends('layout')
@section('title', 'Attendance Register')
@section('content')
<div class="page-header"><h1>Attendance Register</h1></div>

<form method="GET" class="filter-bar">
    <div class="field">
        <label for="date">Date</label>
        <input type="date" name="date" id="date" value="{{ $date }}">
    </div>
    <div class="field">
        <label for="site_id">Site</label>
        <select name="site_id" id="site_id">
            <option value="">All sites</option>
            @foreach($sites as $site)
                <option value="{{ $site->id }}" @selected((string) request('site_id') === (string) $site->id)>{{ $site->name }}</option>
            @endforeach
        </select>
    </div>
    <div class="field">
        <label for="emp_id">Employee</label>
        <input type="text" name="emp_id" id="emp_id" value="{{ request('emp_id') }}" placeholder="emp_id or name">
    </div>
    <button type="submit" class="btn">Filter</button>
</form>

<div class="card">
    <div class="table-wrap">
    <table>
        <thead>
            <tr><th>Time</th><th>Employee</th><th>Direction</th><th>Site</th><th>Source</th><th>Confidence</th><th>Liveness</th><th></th></tr>
        </thead>
        <tbody>
        @forelse($events as $event)
            <tr class="{{ $event->isCorrected() ? 'strike' : '' }}">
                <td>{{ $event->ts->format('Y-m-d H:i:s') }}</td>
                <td>{{ $event->employee->emp_id }} — {{ $event->employee->name }}</td>
                <td>{{ $event->direction }}</td>
                <td>{{ $event->site->name }}</td>
                <td>{{ $event->source }}{{ $event->operator ? ' ('.$event->operator.')' : '' }}</td>
                <td>{{ number_format($event->confidence, 2) }}</td>
                <td>
                    @if($event->liveness_pass)
                        <span class="badge badge-green">pass</span>
                    @else
                        <span class="badge badge-red">flagged</span>
                    @endif
                </td>
                <td>
                    @if($event->isCorrected())
                        <span class="badge badge-gray">corrected</span>
                    @else
                        <a href="{{ route('attendance.correct', $event) }}" class="btn btn-sm">Correct</a>
                    @endif
                </td>
            </tr>
        @empty
            <tr><td colspan="8" class="empty-state">No attendance events found.</td></tr>
        @endforelse
        </tbody>
    </table>
    </div>
    <div class="pagination-wrap">{{ $events->links() }}</div>
</div>
@endsection
