@extends('layouts.app')
@section('title', $student->user->name)
@section('page-title', $student->user->name)
@section('sidebar-nav')
<div class="nav-item"><a href="{{ route('parent.dashboard') }}"><i class="bi bi-grid"></i> Dashboard</a></div>
@foreach(auth()->user()->parentProfile->students as $s)
<div class="nav-item"><a href="{{ route('parent.student', $s->id) }}"><i class="bi bi-person"></i> {{ $s->user->name }}</a></div>
@endforeach
@endsection

@section('content')
<div class="page-header">
    <div style="display:flex;align-items:center;gap:16px;">
        <div class="avatar" style="width:52px;height:52px;font-size:20px;">{{ strtoupper(substr($student->user->name, 0, 1)) }}</div>
        <div>
            <h1>{{ $student->user->name }}</h1>
            <p>{{ $student->stream?->schoolClass->name }} {{ $student->stream?->name }} &bull; Adm: {{ $student->admission_no }}</p>
        </div>
    </div>
    <a href="{{ route('parent.dashboard') }}" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> Back</a>
</div>

<div class="grid grid-3" style="margin-bottom:24px;">
    <div class="stat-card">
        <div class="stat-icon green"><i class="bi bi-check-circle"></i></div>
        <div class="stat-info"><h3>{{ $attendanceSummary['present'] ?? 0 }}</h3><p>Days Present</p></div>
    </div>
    <div class="stat-card">
        <div class="stat-icon red"><i class="bi bi-x-circle"></i></div>
        <div class="stat-info"><h3>{{ $attendanceSummary['absent'] ?? 0 }}</h3><p>Days Absent</p></div>
    </div>
    <div class="stat-card">
        <div class="stat-icon {{ ($currentInvoice?->balance ?? 0) > 0 ? 'red' : 'green' }}"><i class="bi bi-cash"></i></div>
        <div class="stat-info">
            <h3>KES {{ number_format($currentInvoice?->balance ?? 0) }}</h3>
            <p>Fee Balance</p>
        </div>
    </div>
</div>

<div class="grid grid-2">
    <div class="card">
        <div class="card-header"><h5>Recent Results</h5></div>
        <div class="card-body" style="padding:0;">
            @forelse($recentMarks as $mark)
            <div style="padding:12px 20px;border-bottom:1px solid var(--border);display:flex;justify-content:space-between;align-items:center;">
                <div>
                    <div style="font-weight:500;font-size:13px;">{{ $mark->subject->name }}</div>
                    <div style="font-size:12px;color:var(--gray);">{{ $mark->exam->name }}</div>
                </div>
                <div style="text-align:right;">
                    <span style="font-weight:700;">{{ $mark->score }}%</span>
                    <span class="badge badge-info" style="margin-left:6px;">{{ $mark->grade }}</span>
                </div>
            </div>
            @empty
            <div style="padding:20px;text-align:center;color:var(--gray);">No results yet</div>
            @endforelse
        </div>
    </div>
    <div class="card">
        <div class="card-header"><h5>Current Term Fees</h5></div>
        <div class="card-body">
            @if($currentInvoice)
            <div style="margin-bottom:12px;">
                <div style="display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border);">
                    <span style="color:var(--gray);">Total Fee</span>
                    <strong>KES {{ number_format($currentInvoice->total_amount) }}</strong>
                </div>
                <div style="display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border);">
                    <span style="color:var(--gray);">Paid</span>
                    <strong style="color:var(--success);">KES {{ number_format($currentInvoice->amount_paid) }}</strong>
                </div>
                <div style="display:flex;justify-content:space-between;padding:8px 0;">
                    <span style="color:var(--gray);">Balance</span>
                    <strong style="color:{{ $currentInvoice->balance > 0 ? 'var(--danger)' : 'var(--success)' }};">
                        KES {{ number_format($currentInvoice->balance) }}
                    </strong>
                </div>
            </div>
            <span class="badge {{ $currentInvoice->status === 'paid' ? 'badge-success' : ($currentInvoice->status === 'partial' ? 'badge-warning' : 'badge-danger') }}">
                {{ ucfirst($currentInvoice->status) }}
            </span>
            @else
            <div style="text-align:center;color:var(--gray);">No invoice for current term</div>
            @endif
        </div>
    </div>
</div>
@endsection
