@extends('layouts.portal')

@section('title', 'Account '.$account->account_no)

@section('content')
<div class="fundi-page-header">
    <div>
        <h1>{{ $account->account_no }}</h1>
        <p class="fundi-page-header__desc">{{ ucfirst(str_replace('_',' ',$account->account_type)) }} Account</p>
    </div>
    <a href="{{ route('portal.accounts.index') }}" class="fundi-btn fundi-btn--secondary">Back to accounts</a>
</div>

<div class="fundi-stats">
    <div class="fundi-stat fundi-stat--accent">
        <div class="fundi-stat__label">Balance</div>
        <div class="fundi-stat__value">{{ money($account->balance) }}</div>
    </div>
    <div class="fundi-stat">
        <div class="fundi-stat__label">Available</div>
        <div class="fundi-stat__value">{{ money($account->available_balance) }}</div>
    </div>
</div>

<div class="fundi-card">
    <div class="fundi-card__header"><h3>Transaction History</h3></div>
    <div class="fundi-card__body">
        <div class="fundi-table-wrap">
            <table class="fundi-table">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Reference</th>
                        <th>Type</th>
                        <th>Narration</th>
                        <th class="num">Amount</th>
                        <th class="num">Balance After</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($transactions as $txn)
                        <tr>
                            <td>{{ $txn->value_date?->format('d M Y') ?? $txn->created_at->format('d M Y') }}</td>
                            <td>{{ $txn->reference ?? '—' }}</td>
                            <td>{{ ucfirst($txn->txn_type ?? '—') }}</td>
                            <td>{{ $txn->narration ?? '—' }}</td>
                            <td class="num">{{ money($txn->amount) }}</td>
                            <td class="num">{{ money($txn->balance_after) }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="fundi-empty">No transactions yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($transactions->hasPages())
            <div class="fundi-pagination">{{ $transactions->links() }}</div>
        @endif
    </div>
</div>
@endsection
