@extends('layouts.admin')

@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">{{ $account->customer->display_name ?? '—' }} · {{ ucfirst(str_replace('_',' ',$account->account_type)) }}</p>
    </div>
    <a href="{{ route('admin.accounts.index') }}" class="fundi-btn fundi-btn--secondary">Back</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 class="fundi-stat">
        <div class="fundi-stat__label">Lien</div>
        <div class="fundi-stat__value">{{ money($account->lien_amount) }}</div>
    </div>
</div>

<div class="fundi-detail-grid">
    <div class="fundi-detail-item"><label>Status</label><span><x-status-badge :status="$account->status" /></span></div>
    <div class="fundi-detail-item"><label>Currency</label><span>{{ $account->currency }}</span></div>
    <div class="fundi-detail-item"><label>Branch</label><span>{{ $account->branch->name ?? '—' }}</span></div>
    <div class="fundi-detail-item"><label>Opened</label><span>{{ $account->opened_at?->format('d M Y') ?? '—' }}</span></div>
    <div class="fundi-detail-item"><label>Interest Rate</label><span>{{ $account->interest_rate ? $account->interest_rate.'%' : '—' }}</span></div>
</div>

<div class="fundi-card">
    <div class="fundi-card__header"><h3>Recent Transactions</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>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($account->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>{{ Str::limit($txn->narration ?? '—', 40) }}</td>
                            <td class="num">{{ money($txn->amount) }}</td>
                            <td class="num">{{ money($txn->balance_after) }}</td>
                            <td><x-status-badge :status="$txn->status ?? 'posted'" /></td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="fundi-empty">No transactions yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
