@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">User Report</h2>
        <a href="{{ route('reports.user-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-4">
            <input type="text" name="name" class="form-control" placeholder="Search by Name" value="{{ request('name') }}">
        </div>
        <div class="col-md-4">
            <input type="text" name="email" class="form-control" placeholder="Search by Email" value="{{ request('email') }}">
        </div>
        <div class="col-md-2">
            <input type="text" name="role" class="form-control" placeholder="Search by Role" value="{{ request('role') }}">
        </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.user-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>User ID</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Role</th>
                    <th>Created At</th>
                </tr>
            </thead>
            <tbody>
                @forelse($users as $user)
                    <tr>
                        <td>{{ $user->id }}</td>
                        <td>{{ trim($user->first_name . ' ' . $user->last_name) }}</td>
                        <td>{{ $user->email }}</td>
                        <td>{{ $user->roles->pluck('name')->join(', ') }}</td>
                        <td>{{ $user->created_at ? $user->created_at->format('Y-m-d H:i') : '-' }}</td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="text-center">No users found</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
