@extends('layout')
@section('title', 'Employees')
@section('content')
<div class="page-header">
    <h1>Employees</h1>
    <div>
        <a href="{{ route('employees.import.form') }}" class="btn">Import CSV</a>
        <a href="{{ route('employees.create') }}" class="btn btn-primary">Add employee</a>
    </div>
</div>

<form method="GET" class="filter-bar">
    <div class="field">
        <label for="q">Search</label>
        <input type="text" name="q" id="q" value="{{ request('q') }}" 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>Emp ID</th><th>Name</th><th>Active</th><th>Consent</th><th>Templates</th><th>Enrolled</th><th></th></tr>
        </thead>
        <tbody>
        @forelse($employees as $employee)
            <tr>
                <td>{{ $employee->emp_id }}</td>
                <td>{{ $employee->name }}</td>
                <td>
                    @if($employee->active)
                        <span class="badge badge-green">Active</span>
                    @else
                        <span class="badge badge-gray">Inactive</span>
                    @endif
                </td>
                <td>{{ $employee->consent_on?->toDateString() ?? '—' }}</td>
                <td>{{ $employee->face_templates_count }}</td>
                <td>
                    @if($employee->face_templates_count > 0)
                        <span class="badge badge-green">Enrolled</span>
                    @else
                        <span class="badge badge-amber">Not enrolled</span>
                    @endif
                </td>
                <td>
                    <a href="{{ route('employees.edit', $employee) }}" class="btn btn-sm">Edit</a>
                    <form method="POST" action="{{ route('employees.destroy', $employee) }}" style="display:inline" onsubmit="return confirm('Remove this employee?')">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn btn-sm btn-danger">Remove</button>
                    </form>
                </td>
            </tr>
        @empty
            <tr><td colspan="7" class="empty-state">No employees found.</td></tr>
        @endforelse
        </tbody>
    </table>
    </div>
    <div class="pagination-wrap">{{ $employees->links() }}</div>
</div>
@endsection
