@extends('layouts.user', ['heading' => $title])

@section('content')
    <div class="mb-4 flex flex-wrap items-center gap-3">
        <form method="GET" class="flex flex-wrap items-center gap-2">
            <input type="date" name="from" value="{{ $from }}" class="rounded border p-2" />
            <input type="date" name="to" value="{{ $to }}" class="rounded border p-2" />
            <button class="rounded bg-slate-900 px-4 py-2 text-white">Filter</button>
        </form>

        <div class="ml-auto flex gap-2">
            <a href="{{ request()->fullUrlWithQuery(['export' => 'excel']) }}" class="rounded bg-emerald-600 px-3 py-2 text-white">Export Excel</a>
            <a href="{{ request()->fullUrlWithQuery(['export' => 'pdf']) }}" class="rounded bg-slate-700 px-3 py-2 text-white">Export PDF</a>
        </div>
    </div>

    <div class="overflow-x-auto rounded bg-white shadow">
        <table class="min-w-full text-sm">
            <thead class="bg-slate-100 text-left">
                <tr>
                    @foreach($headings as $heading)
                        <th class="p-3">{{ $heading }}</th>
                    @endforeach
                </tr>
            </thead>
            <tbody>
                @forelse($rows as $row)
                    <tr class="border-t">
                        @foreach($row as $cell)
                            <td class="p-3">{{ $cell }}</td>
                        @endforeach
                    </tr>
                @empty
                    <tr>
                        <td colspan="{{ count($headings) }}" class="p-4 text-center text-slate-500">No records found.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
@endsection
