@extends('layouts.admin')

@section('content')
<div class="container mx-auto px-4 py-8">
    <h1 class="text-3xl font-bold text-gray-900 mb-6">All Transactions</h1>

    <form method="GET" action="" class="mb-6 space-y-2 md:space-y-0 md:flex md:items-center md:space-x-4">
        <input type="text" name="search" placeholder="Ticket/User/Team" value="{{ request('search') }}" class="p-2 border rounded w-48">
        <input type="text" name="user" placeholder="User Name" value="{{ request('user') }}" class="p-2 border rounded w-36">
        <select name="payment_method" class="p-2 border rounded">
            <option value="">All Methods</option>
            <option value="cash" @if(request('payment_method') == 'cash') selected @endif>Cash</option>
            <option value="mobile money" @if(request('payment_method') == 'mobile money') selected @endif>Mobile Money</option>
            <option value="card" @if(request('payment_method') == 'card') selected @endif>Card</option>
        </select>
        <input type="date" name="from" value="{{ request('from') }}" class="p-2 border rounded">
        <input type="date" name="to" value="{{ request('to') }}" class="p-2 border rounded">
        <button class="bg-indigo-600 text-white p-2 rounded" type="submit">Filter</button>
        <a href="{{ route('admin.transactions.index') }}" class="p-2 text-gray-400 hover:text-gray-700">Reset</a>
        <a href="{{ route('admin.transactions.exportCsv', request()->query()) }}" class="bg-green-500 text-white p-2 rounded ml-3"><i class="fas fa-file-csv mr-1"></i>Export CSV</a>
        <a href="{{ route('admin.transactions.exportPdf', request()->query()) }}" class="bg-red-500 text-white p-2 rounded ml-2"><i class="fas fa-file-pdf mr-1"></i>Export PDF</a>
    </form>

    <div class="bg-white shadow-md rounded-lg overflow-hidden">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Ticket No</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">User</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Match</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Amount</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Payment Method</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Date/Time</th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                @forelse($transactions as $txn)
                <tr>
                    <td class="px-6 py-4 whitespace-nowrap text-sm">{{ $txn->ticket->ticket_number ?? '-' }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm">{{ $txn->user->name ?? '-' }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                        {{ $txn->ticket->match->home_team ?? '-' }} vs {{ $txn->ticket->match->away_team ?? '-' }}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm">SSP {{ number_format($txn->amount, 2) }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm">{{ ucfirst($txn->payment_method) }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-600">{{ $txn->created_at->format('M d, Y H:i') }}</td>
                </tr>
                @empty
                <tr>
                    <td colspan="6" class="px-6 py-4 text-center text-gray-500">No transactions found.</td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $transactions->links() }}</div>
</div>
@endsection
