@extends('layouts.parent')
@section('title', $challan->challan_number)
@section('page_title', 'Challan ' . $challan->challan_number)

@section('content')
    <div class="mb-2"><a href="{{ route('parent.fees') }}" class="btn btn-sm btn-light border"><i class="bi bi-arrow-left me-1"></i>Back to Fees</a></div>
    <div class="card">
        <div class="card-header d-flex justify-content-between">
            <span><i class="bi bi-receipt me-1"></i>{{ $challan->title }}</span>
            <span class="badge bg-soft-{{ $challan->status_color }} text-capitalize">{{ $challan->status }}</span>
        </div>
        <div class="card-body">
            <table class="table table-sm align-middle">
                <thead><tr><th>Student</th><th>Fee Head</th><th class="text-end">Amount</th><th class="text-end">Discount</th><th class="text-end">Net</th></tr></thead>
                <tbody>
                    @foreach($challan->items as $item)
                        <tr>
                            <td class="small">{{ $item->student?->name }}</td>
                            <td class="small">{{ $item->feeType?->name }}</td>
                            <td class="text-end">{{ number_format($item->amount) }}</td>
                            <td class="text-end text-success">{{ $item->discount > 0 ? '-'.number_format($item->discount) : '—' }}</td>
                            <td class="text-end fw-semibold">{{ number_format($item->net) }}</td>
                        </tr>
                    @endforeach
                </tbody>
                <tfoot class="table-light fw-bold"><tr><td colspan="4" class="text-end">Net Payable</td><td class="text-end">{{ number_format($challan->net_payable) }}</td></tr>
                    <tr><td colspan="4" class="text-end">Paid</td><td class="text-end text-success">{{ number_format($challan->paid_amount) }}</td></tr>
                    <tr><td colspan="4" class="text-end">Balance</td><td class="text-end {{ $challan->balance > 0 ? 'text-danger' : '' }}">{{ number_format($challan->balance) }}</td></tr>
                </tfoot>
            </table>
            @if($challan->due_date && $challan->balance > 0)
                <div class="alert alert-warning small mb-0"><i class="bi bi-calendar-event me-1"></i>Please pay by <strong>{{ $challan->due_date->format('d M Y') }}</strong> at the school accounts office.</div>
            @endif
        </div>
    </div>
@endsection
