@extends('admin.admin_master')

@section('admin')
<br/><br/>
<div class="container mx-auto p-4 mt-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2 class="text-2xl font-bold mb-0">Task Report</h2>
        <a href="{{ route('reports.task-report.pdf', request()->query()) }}" class="btn btn-danger btn-sm text-white">
            <span style="font-size:1.2em;vertical-align:middle;">&#128462;</span> Download PDF
        </a>
    </div>
    <form method="GET" class="row g-2 mb-4">
        <div class="col-md-3">
            <input type="text" name="status" class="form-control" placeholder="Search by Status" value="{{ request('status') }}">
        </div>
        <div class="col-md-3">
            <input type="text" name="assigned_user" class="form-control" placeholder="Search by Assigned User" value="{{ request('assigned_user') }}">
        </div>
        <div class="col-md-3">
            <input type="text" name="assigned_role" class="form-control" placeholder="Search by Assigned Role" value="{{ request('assigned_role') }}">
        </div>
        <div class="col-md-2">
            <input type="text" name="workflow_instance" class="form-control" placeholder="Workflow Instance ID" value="{{ request('workflow_instance') }}">
        </div>
        <div class="col-md-1">
            <button type="submit" class="btn btn-primary w-100">Search</button>
        </div>
        <div class="col-md-1">
            <a href="{{ route('reports.task-report') }}" class="btn btn-secondary w-100 text-white">Reset</a>
        </div>
    </form>
    <div class="table-responsive">
        <table class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th>Task ID</th>
                    <th>Status</th>
                    <th>Assigned User</th>
                    <th>Assigned Role</th>
                    <th>Workflow Instance</th>
                    <th>Created At</th>
                </tr>
            </thead>
            <tbody>
                @forelse($tasks as $task)
                    <tr>
                        <td>{{ $task->id }}</td>
                        <td>{{ ucfirst($task->status) }}</td>
                        <td>{{ $task->assignedUser->first_name ?? '-' }} {{ $task->assignedUser->last_name ?? '' }}</td>
                        <td>{{ $task->assignedRole->name ?? '-' }}</td>
                        <td>{{ $task->instance->id ?? '-' }}</td>
                        <td>{{ $task->created_at ? $task->created_at->format('Y-m-d H:i') : '-' }}</td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="text-center">No tasks found</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
