@extends('layouts.portal')

@section('title', 'My Loans')

@section('content')
<h1>My Loans</h1>
<p class="text-muted" style="margin-bottom:1.5rem;">Track your loan facilities and repayment schedules.</p>

<div class="fundi-card">
    <div class="fundi-card__body">
        <div class="fundi-table-wrap">
            <table class="fundi-table">
                <thead>
                    <tr>
                        <th>Loan No.</th>
                        <th>Product</th>
                        <th class="num">Principal</th>
                        <th class="num">Outstanding</th>
                        <th>Tenor</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($loans as $loan)
                        <tr>
                            <td>{{ $loan->loan_no }}</td>
                            <td>{{ $loan->loanProduct->name ?? '—' }}</td>
                            <td class="num">{{ money($loan->principal) }}</td>
                            <td class="num">{{ money($loan->outstanding_principal) }}</td>
                            <td>{{ $loan->tenor_months }} mo</td>
                            <td><x-status-badge :status="$loan->status" /></td>
                            <td class="actions"><a href="{{ route('portal.loans.show', $loan) }}" class="fundi-btn fundi-btn--link fundi-btn--sm">Details</a></td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="fundi-empty">No loans on file.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($loans->hasPages())
            <div class="fundi-pagination">{{ $loans->links() }}</div>
        @endif
    </div>
</div>
@endsection
