@extends('eliteadmin::layouts.app')

@section('title', 'Transactions')

@section('content')
    <div class="page-header d-flex justify-content-between align-items-start flex-wrap gap-2">
        <div><h1 class="page-title">Transactions</h1></div>
        @can('finance.transactions.create')
            <a href="{{ route('finance.transactions.create') }}" class="btn btn-primary btn-sm">Add Transaction</a>
        @endcan
    </div>

    @include('finance::partials.filters')

    <div class="card">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-light">
                    <tr><th>Date</th><th>Type</th><th>Category</th><th>Amount</th><th>Reference</th><th class="text-end">Actions</th></tr>
                </thead>
                <tbody>
                    @forelse ($transactions as $transaction)
                        <tr>
                            <td>{{ $transaction->transaction_at->format('M j, Y H:i') }}</td>
                            <td><span class="badge bg-{{ $transaction->type->value === 'income' ? 'success' : 'danger' }}">{{ ucfirst($transaction->type->value) }}</span></td>
                            <td>{{ $transaction->categoryName() }}</td>
                            <td>{{ platform_money($transaction->amount) }}</td>
                            <td>{{ $transaction->reference_number ?? '—' }}</td>
                            <td class="text-end">
                                <a href="{{ route('finance.transactions.show', $transaction) }}" class="btn btn-sm btn-outline-secondary">View</a>
                                @can('finance.transactions.update')
                                    <a href="{{ route('finance.transactions.edit', $transaction) }}" class="btn btn-sm btn-outline-primary">Edit</a>
                                @endcan
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-4">No transactions found</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if ($transactions->hasPages())
            <div class="card-footer">{{ $transactions->links() }}</div>
        @endif
    </div>
@endsection
