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

<form method="GET" class="filter-bar">
    <div class="field">
        <label for="from">From</label>
        <input type="date" name="from" id="from" value="{{ $from }}">
    </div>
    <div class="field">
        <label for="to">To</label>
        <input type="date" name="to" id="to" value="{{ $to }}">
    </div>
    <button type="submit" class="btn">Run report</button>
    <a href="{{ route('reports.daily.export', request()->query()) }}" class="btn btn-primary">Export CSV</a>
</form>

<div class="card">
    <div class="table-wrap">
    <table>
        <thead>
            <tr><th>Date</th><th>Emp ID</th><th>Name</th><th>First IN</th><th>Last OUT</th><th>Worked (min)</th><th>Late</th><th>Early out</th><th>Status</th></tr>
        </thead>
        <tbody>
        @forelse($rows as $row)
            <tr>
                <td>{{ $row->date->toDateString() }}</td>
                <td>{{ $row->employee->emp_id }}</td>
                <td>{{ $row->employee->name }}</td>
                <td>{{ $row->first_in?->format('H:i:s') ?? '—' }}</td>
                <td>{{ $row->last_out?->format('H:i:s') ?? '—' }}</td>
                <td>{{ $row->worked_minutes ?? '—' }}</td>
                <td>{{ $row->late ? 'Yes' : 'No' }}</td>
                <td>{{ $row->early_out ? 'Yes' : 'No' }}</td>
                <td>
                    @if($row->status === 'present')
                        <span class="badge badge-green">present</span>
                    @elseif($row->status === 'absent')
                        <span class="badge badge-red">absent</span>
                    @else
                        <span class="badge badge-amber">manual</span>
                    @endif
                </td>
            </tr>
        @empty
            <tr><td colspan="9" class="empty-state">No data for this range.</td></tr>
        @endforelse
        </tbody>
    </table>
    </div>
</div>
@endsection
