@extends('layouts.admin')

@section('title', 'Portfolio Report')

@section('content')
@include('admin.reports._nav', ['active' => 'portfolio'])

<div class="fundi-stats">
    <div class="fundi-stat fundi-stat--accent">
        <div class="fundi-stat__label">Total Loans</div>
        <div class="fundi-stat__value">{{ number_format($totals['loan_count']) }}</div>
    </div>
    <div class="fundi-stat">
        <div class="fundi-stat__label">Active Loans</div>
        <div class="fundi-stat__value">{{ number_format($totals['active_count']) }}</div>
    </div>
    <div class="fundi-stat fundi-stat--accent">
        <div class="fundi-stat__label">Total Outstanding</div>
        <div class="fundi-stat__value">{{ money($totals['total_outstanding']) }}</div>
    </div>
</div>

<div class="fundi-grid-2">
    <div class="fundi-card">
        <div class="fundi-card__header"><h3>By Status</h3></div>
        <div class="fundi-card__body">
            <div class="fundi-table-wrap">
                <table class="fundi-table">
                    <thead><tr><th>Status</th><th class="num">Count</th><th class="num">Principal</th><th class="num">Outstanding</th></tr></thead>
                    <tbody>
                        @forelse($portfolioByStatus as $row)
                            <tr>
                                <td><x-status-badge :status="$row->status" /></td>
                                <td class="num">{{ number_format($row->count) }}</td>
                                <td class="num">{{ money($row->total_principal) }}</td>
                                <td class="num">{{ money($row->outstanding) }}</td>
                            </tr>
                        @empty
                            <tr><td colspan="4" class="fundi-empty">No data.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="fundi-card">
        <div class="fundi-card__header"><h3>By Product</h3></div>
        <div class="fundi-card__body">
            <div class="fundi-table-wrap">
                <table class="fundi-table">
                    <thead><tr><th>Product</th><th class="num">Count</th><th class="num">Outstanding</th></tr></thead>
                    <tbody>
                        @forelse($portfolioByProduct as $row)
                            <tr>
                                <td>{{ $row->product_name }}</td>
                                <td class="num">{{ number_format($row->count) }}</td>
                                <td class="num">{{ money($row->outstanding) }}</td>
                            </tr>
                        @empty
                            <tr><td colspan="3" class="fundi-empty">No data.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@endsection
