@extends('layouts.app')

@section('title', 'Report Results | Institution Axis')

@section('sidebar-menu')
    @include('schooladmin.partials.sidebar')
@endsection

@section('breadcrumb')
    <span><a href="{{ route('schooladmin.dashboard') }}">Home</a></span> / 
    <span><a href="{{ route('schooladmin.reports.index') }}">Reports</a></span> / 
    <span><a href="{{ route('schooladmin.reports.custom') }}">Custom Builder</a></span> / 
    <span class="active-page">Results</span>
@endsection

@section('content')
<div class="container-fluid p-0">
    <div class="card shadow-sm border-0 rounded-4">
        <div class="card-header bg-white border-0 py-3 d-flex justify-content-between align-items-center">
            <h5 class="mb-0 fw-bold">
                <i class="fas fa-file-alt me-2 text-primary"></i> 
                {{ ucwords(str_replace('_', ' ', $reportType)) }}
            </h5>
            <div class="actions">
                <button class="btn btn-sm btn-outline-primary" onclick="window.print()"><i class="fas fa-print me-1"></i> Print</button>
                <button class="btn btn-sm btn-success"><i class="fas fa-file-excel me-1"></i> Export CSV</button>
            </div>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                @if($reportType == 'student_performance')
                <table class="table table-hover table-striped mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4">Student</th>
                            <th>Class</th>
                            <th>Subject</th>
                            <th>Exam Type</th>
                            <th>Score</th>
                            <th class="text-end pe-4">Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data as $row)
                        <tr>
                            <td class="ps-4">{{ $row->student->fullName() }}</td>
                            <td>{{ $row->schoolClass->name }} {{ $row->schoolClass->stream }}</td>
                            <td>{{ $row->subject->name }}</td>
                            <td>{{ $row->exam_type }}</td>
                            <td><span class="badge {{ $row->score >= 50 ? 'bg-success' : 'bg-danger' }}">{{ $row->score }}%</span></td>
                            <td class="text-end pe-4">{{ $row->created_at->format('M d, Y') }}</td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
                @elseif($reportType == 'fee_balances')
                <table class="table table-hover table-striped mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4">Student</th>
                            <th>Invoice #</th>
                            <th>Class</th>
                            <th>Total Amount</th>
                            <th>Paid</th>
                            <th class="text-danger">Balance</th>
                            <th class="text-end pe-4">Due Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data as $row)
                        <tr>
                            <td class="ps-4">{{ $row->student->fullName() }}</td>
                            <td>{{ $row->invoice_number }}</td>
                            <td>{{ $row->student->schoolClass->name }}</td>
                            <td>{{ number_format($row->total_amount) }}</td>
                            <td>{{ number_format($row->paid_amount) }}</td>
                            <td class="text-danger fw-bold">{{ number_format($row->total_amount - $row->paid_amount) }}</td>
                            <td class="text-end pe-4">{{ $row->due_date->format('M d, Y') }}</td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
                @endif

                @if($data->isEmpty())
                <div class="text-center py-5">
                    <i class="fas fa-folder-open fa-3x text-muted mb-3"></i>
                    <p class="text-muted">No data found matching your filters.</p>
                    <a href="{{ route('schooladmin.reports.custom') }}" class="btn btn-primary btn-sm rounded-pill px-4">Go Back</a>
                </div>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
