@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">Workflow Report</h2>
        <a href="{{ route('reports.workflow-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 Workflow Name" value="{{ request('name') }}">
        </div>
        <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="created_by" class="form-control" placeholder="Search by Created By" value="{{ request('created_by') }}">
        </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.workflow-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>Name</th>
                    <th>Status</th>
                    <th>Created By</th>
                    <th>Created At</th>
                </tr>
            </thead>
            <tbody>
                @forelse($workflows as $workflow)
                    <tr>
                        <td>{{ $workflow->name }}</td>
                        <td>{{ ucfirst($workflow->status) }}</td>
                        <td>{{ $workflow->createdBy->first_name ?? '-' }} {{ $workflow->createdBy->last_name ?? '' }}</td>
                        <td>{{ $workflow->created_at ? $workflow->created_at->format('Y-m-d H:i') : '-' }}</td>
                    </tr>
                @empty
                    <tr><td colspan="4" class="text-center">No workflows found</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
