@extends('layouts.app')
@section('title', $title)
@section('page_title', $title)
@section('breadcrumbs')
    <li class="breadcrumb-item"><a href="{{ route('reports.index') }}">Reports</a></li><li class="breadcrumb-item active">Fee Collection</li>
@endsection
@section('page_actions')@include('reports._export', ['route' => 'reports.fee-collection'])@endsection

@section('content')
    <div class="card mb-3"><div class="card-body py-2">
        <form method="GET" class="row g-2 align-items-end">
            <div class="col-md-3"><label class="form-label small">From</label><input type="date" name="from" value="{{ $from }}" class="form-control form-control-sm"></div>
            <div class="col-md-3"><label class="form-label small">To</label><input type="date" name="to" value="{{ $to }}" class="form-control form-control-sm"></div>
            <div class="col-md-3"><label class="form-label small">Search</label>
                <input type="text" name="search" value="{{ $search ?? '' }}" class="form-control form-control-sm" placeholder="Student, receipt, challan, family…"></div>
            <div class="col-md-3"><button class="btn btn-sm btn-primary"><i class="bi bi-funnel me-1"></i>Generate</button>
                <a href="{{ route('reports.fee-collection') }}" class="btn btn-sm btn-light border">Reset</a></div>
        </form>
    </div></div>

    <div class="row g-3 mb-3">
        <div class="col-md-4"><div class="card stat-card"><div class="card-body d-flex align-items-center gap-3">
            <div class="icon bg-soft-success"><i class="bi bi-cash-stack"></i></div>
            <div><div class="value" style="font-size:1.3rem">Rs {{ number_format($total) }}</div><div class="label">Total Collected</div></div>
        </div></div></div>
        @foreach($byMethod as $method => $amt)
            <div class="col-md-2"><div class="card"><div class="card-body py-2 text-center">
                <div class="small text-muted">{{ App\Models\FeePayment::METHODS[$method] ?? ucfirst($method) }}</div><div class="fw-semibold">Rs {{ number_format($amt) }}</div>
            </div></div></div>
        @endforeach
    </div>

    <div class="card"><div class="card-body">
        <table class="table table-sm table-hover align-middle">
            <thead><tr><th>Student</th><th>Date</th><th>Challan</th><th>Class</th><th>Method</th><th class="text-end">Amount</th></tr></thead>
            <tbody>
                @forelse($payments as $p)
                    <tr>
                        <td class="small fw-semibold">{{ $studentNames($p) }}</td>
                        <td class="small">{{ $p->payment_date->format('d M Y') }}</td>
                        <td class="small">{{ $p->challan?->challan_number }}</td>
                        <td class="small">{{ $classNames($p) }}</td>
                        <td class="small">{{ $p->method_label }}</td>
                        <td class="text-end fw-semibold">{{ number_format($p->amount) }}</td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="text-center text-muted py-3">No collections in this period.</td></tr>
                @endforelse
            </tbody>
            <tfoot class="table-light fw-bold"><tr><td colspan="5" class="text-end">Total</td><td class="text-end">{{ number_format($total) }}</td></tr></tfoot>
        </table>
    </div></div>
@endsection
