@extends('layouts.app')

@section('title', 'Transactions')

@section('content')
<div class="space-y-6">
    <div>
        <h1 class="text-2xl font-bold text-gray-900">Transactions</h1>
        <p class="mt-1 text-sm text-gray-500">View all your transactions.</p>
    </div>

    <div class="rounded-xl bg-white shadow-sm border border-gray-100 overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-100">
            <form method="GET" class="flex gap-3">
                <select name="type" class="rounded-lg border-gray-300 text-sm focus:border-green-950 focus:ring-green-950">
                    <option value="">All Types</option>
                    <option value="airtime" {{ request('type') === 'airtime' ? 'selected' : '' }}>Airtime</option>
                    <option value="data" {{ request('type') === 'data' ? 'selected' : '' }}>Data</option>
                    <option value="cable" {{ request('type') === 'cable' ? 'selected' : '' }}>Cable</option>
                    <option value="electricity" {{ request('type') === 'electricity' ? 'selected' : '' }}>Electricity</option>
                    <option value="exam_pin" {{ request('type') === 'exam_pin' ? 'selected' : '' }}>Exam PIN</option>
                </select>
                <select name="status" class="rounded-lg border-gray-300 text-sm focus:border-green-950 focus:ring-green-950">
                    <option value="">All Status</option>
                    <option value="successful" {{ request('status') === 'successful' ? 'selected' : '' }}>Successful</option>
                    <option value="pending" {{ request('status') === 'pending' ? 'selected' : '' }}>Pending</option>
                    <option value="failed" {{ request('status') === 'failed' ? 'selected' : '' }}>Failed</option>
                </select>
                <button type="submit" class="rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-200">Filter</button>
            </form>
        </div>

        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-100">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Service</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Reference</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Customer</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">Status</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Date</th>
                        <th class="px-6 py-3"></th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-50">
                    @forelse($transactions as $tx)
                    <tr class="hover:bg-gray-50">
                        <td class="px-6 py-4 text-sm font-medium text-gray-900">{{ $tx->service_name }}</td>
                        <td class="px-6 py-4 text-sm text-gray-500 font-mono">{{ $tx->reference }}</td>
                        <td class="px-6 py-4 text-sm text-gray-500">{{ $tx->customer_number }}</td>
                        <td class="px-6 py-4 text-sm font-semibold text-gray-900">₦{{ number_format($tx->total_amount, 2) }}</td>
                        <td class="px-6 py-4">
                            @if($tx->status === 'successful')
                                <span class="inline-flex items-center rounded-full bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-inset ring-green-950/20">Successful</span>
                            @elseif($tx->status === 'pending')
                                <span class="inline-flex items-center rounded-full bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-700 ring-1 ring-inset ring-yellow-600/20">Pending</span>
                            @elseif($tx->status === 'failed')
                                <span class="inline-flex items-center rounded-full bg-red-50 px-2 py-1 text-xs font-medium text-red-700 ring-1 ring-inset ring-red-600/20">Failed</span>
                            @elseif($tx->status === 'refunded')
                                <span class="inline-flex items-center rounded-full bg-blue-50 px-2 py-1 text-xs font-medium text-blue-700 ring-1 ring-inset ring-blue-600/20">Refunded</span>
                            @else
                                <span class="inline-flex items-center rounded-full bg-gray-50 px-2 py-1 text-xs font-medium text-gray-700 ring-1 ring-inset ring-gray-600/20">{{ ucfirst($tx->status) }}</span>
                            @endif
                        </td>
                        <td class="px-6 py-4 text-sm text-gray-500">{{ $tx->created_at->format('M d, Y H:i') }}</td>
                        <td class="px-6 py-4 text-right">
                            <a href="{{ route('transactions.show', $tx->reference) }}" class="text-sm font-medium text-green-950 hover:text-green-700">View</a>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="7" class="px-6 py-12 text-center text-sm text-gray-500">No transactions found.</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="px-6 py-4">{{ $transactions->links('vendor.pagination.tailwind') }}</div>
    </div>
</div>
@endsection
