@extends('layouts.app')

@section('title', 'SaaS Payments History')

@section('content')
<div class="space-y-6">
    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">SaaS Payments Ledger</h1>
            <p class="text-xs text-slate-500">Record of all offline, bank transfer, and gateway payments received from tenants.</p>
        </div>
        <a href="{{ route('platform.billing.create_payment') }}" class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white font-bold text-xs rounded-xl shadow-sm">
            + Record Manual Payment
        </a>
    </div>

    <!-- Payments Table (Requirement 30) -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700/60 shadow-sm overflow-hidden text-xs">
        <div class="overflow-x-auto">
            <table class="w-full text-left rtl:text-right">
                <thead class="bg-slate-50 dark:bg-slate-900/60 border-b border-slate-200 dark:border-slate-700 text-slate-500 uppercase tracking-wider font-bold">
                    <tr>
                        <th class="px-6 py-4">Payment #</th>
                        <th class="px-6 py-4">Tenant Company</th>
                        <th class="px-6 py-4">Date</th>
                        <th class="px-6 py-4">Method</th>
                        <th class="px-6 py-4">Reference</th>
                        <th class="px-6 py-4">Amount</th>
                        <th class="px-6 py-4">Recorded By</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-200 dark:divide-slate-700/60 font-medium">
                    @foreach($payments as $payment)
                        <tr class="hover:bg-slate-50 dark:hover:bg-slate-700/30">
                            <td class="px-6 py-4 font-mono font-bold text-emerald-600 dark:text-emerald-400">{{ $payment->payment_number }}</td>
                            <td class="px-6 py-4 font-bold text-slate-900 dark:text-white">{{ $payment->tenant->company_name }}</td>
                            <td class="px-6 py-4 text-slate-500">{{ $payment->payment_date->format('d M Y') }}</td>
                            <td class="px-6 py-4">
                                <span class="px-2.5 py-0.5 rounded-full bg-slate-100 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-bold uppercase text-[10px]">
                                    {{ str_replace('_', ' ', $payment->payment_method) }}
                                </span>
                            </td>
                            <td class="px-6 py-4 font-mono text-slate-500">{{ $payment->transaction_reference ?? 'N/A' }}</td>
                            <td class="px-6 py-4 font-extrabold text-emerald-600 dark:text-emerald-400">AED {{ number_format($payment->amount, 2) }}</td>
                            <td class="px-6 py-4 text-slate-400">{{ $payment->receiver ? $payment->receiver->name : 'System' }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div class="p-4 border-t border-slate-200 dark:border-slate-700">
            {{ $payments->links() }}
        </div>
    </div>
</div>
@endsection
