@extends('customer.layouts.app')

@section('title', 'Payment History')

@section('page-title', 'Payment History')

@section('content')
<div class="max-w-7xl mx-auto">
    <!-- Filters -->
    <div class="bg-white dark:bg-[#1e2630] rounded-xl shadow-sm border border-[#e5e7eb] dark:border-gray-700 p-6 mb-6">
        <form method="GET" action="{{ route('customer.payments.index') }}" class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div>
                <label class="block text-sm font-medium text-[#111418] dark:text-white mb-2">Status</label>
                <select name="status" class="w-full h-11 rounded-lg border border-[#dbe0e6] bg-white dark:bg-[#111418] px-3 py-2 text-sm outline-none focus:border-primary focus:ring-1 focus:ring-primary dark:text-white">
                    <option value="">All Statuses</option>
                    <option value="pending" {{ request('status') == 'pending' ? 'selected' : '' }}>Pending</option>
                    <option value="completed" {{ request('status') == 'completed' ? 'selected' : '' }}>Completed</option>
                    <option value="failed" {{ request('status') == 'failed' ? 'selected' : '' }}>Failed</option>
                    <option value="refunded" {{ request('status') == 'refunded' ? 'selected' : '' }}>Refunded</option>
                </select>
            </div>
            <div>
                <label class="block text-sm font-medium text-[#111418] dark:text-white mb-2">From Date</label>
                <input type="date" name="date_from" value="{{ request('date_from') }}" class="w-full h-11 rounded-lg border border-[#dbe0e6] bg-white dark:bg-[#111418] px-3 py-2 text-sm outline-none focus:border-primary focus:ring-1 focus:ring-primary dark:text-white">
            </div>
            <div>
                <label class="block text-sm font-medium text-[#111418] dark:text-white mb-2">To Date</label>
                <input type="date" name="date_to" value="{{ request('date_to') }}" class="w-full h-11 rounded-lg border border-[#dbe0e6] bg-white dark:bg-[#111418] px-3 py-2 text-sm outline-none focus:border-primary focus:ring-1 focus:ring-primary dark:text-white">
            </div>
            <div class="md:col-span-3 flex gap-2">
                <button type="submit" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-blue-600 transition-colors">Filter</button>
                <a href="{{ route('customer.payments.index') }}" class="px-4 py-2 border border-[#dbe0e6] text-[#617589] rounded-lg hover:bg-background-light transition-colors">Clear</a>
            </div>
        </form>
    </div>

    <!-- Payments Table -->
    <div class="bg-white dark:bg-[#1e2630] rounded-xl shadow-sm border border-[#e5e7eb] dark:border-gray-700 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left">
                <thead class="bg-background-light dark:bg-[#111418] border-b border-[#e5e7eb]">
                    <tr>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Payment #</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Invoice</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Date</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Method</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider text-right">Amount</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Status</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider text-right">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-[#e5e7eb]">
                    @forelse($payments as $payment)
                        <tr class="hover:bg-background-light/50 transition-colors">
                            <td class="py-4 px-4">
                                <a href="{{ route('customer.payments.show', $payment->id) }}" class="text-primary hover:underline font-medium">
                                    {{ $payment->payment_number }}
                                </a>
                            </td>
                            <td class="py-4 px-4 text-sm text-[#111418] dark:text-white">
                                <a href="{{ route('customer.invoices.show', $payment->invoice_id) }}" class="text-primary hover:underline">
                                    {{ $payment->invoice->invoice_number }}
                                </a>
                            </td>
                            <td class="py-4 px-4 text-sm text-[#617589]">
                                {{ $payment->payment_date->format('M d, Y') }}
                            </td>
                            <td class="py-4 px-4 text-sm text-[#617589]">
                                {{ ucfirst(str_replace('_', ' ', $payment->payment_method)) }}
                            </td>
                            <td class="py-4 px-4 text-sm font-medium text-[#111418] dark:text-white text-right">
                                {{ \App\Models\Currency::formatAmount($payment->amount, $payment->currency) }}
                            </td>
                            <td class="py-4 px-4">
                                @php
                                    $statusColors = [
                                        'pending' => 'bg-yellow-100 text-yellow-700',
                                        'completed' => 'bg-green-100 text-green-700',
                                        'failed' => 'bg-red-100 text-red-700',
                                        'refunded' => 'bg-gray-100 text-gray-700',
                                    ];
                                @endphp
                                <span class="px-2 py-1 rounded-full text-xs font-medium {{ $statusColors[$payment->status] ?? 'bg-gray-100 text-gray-700' }}">
                                    {{ ucfirst($payment->status) }}
                                </span>
                            </td>
                            <td class="py-4 px-4 text-right">
                                <a href="{{ route('customer.payments.show', $payment->id) }}" class="text-primary hover:underline text-sm">View</a>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="py-8 px-4 text-center text-[#617589]">No payments found</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($payments->hasPages())
            <div class="p-4 border-t border-[#e5e7eb]">
                {{ $payments->links() }}
            </div>
        @endif
    </div>
</div>
@endsection



