@extends('layouts.app')

@section('title', 'Payment Receipt | Institution Axis')

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

@section('sidebar-footer')
    <p>{{ auth()->user()->school?->name ?? 'Institution Axis' }}</p>
@endsection

@section('breadcrumb')
    <span><a href="{{ route('schooladmin.dashboard') }}">Home</a></span> / <span>Finance</span> / <span><a href="{{ route('schooladmin.finance.payments.index') }}">Payments</a></span> / <span class="active-page">Receipt</span>
@endsection

@section('content')
<div class="container-fluid">
    <div class="d-flex justify-content-center mb-4 d-print-none">
        <button onclick="window.print()" class="btn btn-secondary rounded-pill px-5 shadow-sm">
            <i class="fas fa-print me-2"></i>Print Official Receipt
        </button>
        <a href="{{ route('schooladmin.finance.payments.index') }}" class="btn btn-outline-secondary rounded-pill px-4 ms-2">
            Back to List
        </a>
    </div>

    <div class="row justify-content-center receipt-container">
        <div class="col-md-7">
            <div class="card shadow-lg border-0 rounded-0 receipt-card">
                <div class="card-body p-0">
                    <div class="receipt-header p-4 bg-light flex-column d-flex align-items-center border-bottom">
                        <i class="fas fa-school fa-3x text-primary mb-2"></i>
                        <h4 class="fw-bold text-dark mb-0">{{ Auth::user()->school->name }}</h4>
                        <p class="text-muted small mb-0">Official Fee Receipt</p>
                    </div>
                    
                    <div class="p-5">
                        <div class="d-flex justify-content-between mb-4 pb-2 border-bottom">
                            <div>
                                <h6 class="text-muted small mb-1 uppercase">Receipt Number</h6>
                                <p class="fw-bold mb-0">REC-{{ str_pad($payment->id, 6, '0', STR_PAD_LEFT) }}</p>
                            </div>
                            <div class="text-end">
                                <h6 class="text-muted small mb-1 uppercase">Date Issued</h6>
                                <p class="fw-bold mb-0">{{ date('d M, Y', strtotime($payment->payment_date)) }}</p>
                            </div>
                        </div>

                        <div class="mb-5">
                            <table class="table table-borderless table-sm">
                                <tr>
                                    <td class="text-muted" style="width: 150px;">Student Name:</td>
                                    <td class="fw-bold">{{ $payment->student->fullName() }}</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Admission No:</td>
                                    <td class="fw-bold">{{ $payment->student->admission_number }}</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Class:</td>
                                    <td class="fw-bold">{{ $payment->student->schoolClass->name }}</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Invoice Ref:</td>
                                    <td class="fw-bold">{{ $payment->invoice->invoice_number }}</td>
                                </tr>
                            </table>
                        </div>

                        <div class="p-4 bg-light rounded-2 border mb-5">
                            <div class="d-flex justify-content-between align-items-center mb-2">
                                <span class="h6 mb-0">Amount Paid:</span>
                                <span class="h4 mb-0 fw-bold">KES {{ number_format($payment->amount, 2) }}</span>
                            </div>
                            <div class="d-flex justify-content-between align-items-center">
                                <span class="text-muted small">Payment Method:</span>
                                <span class="text-muted small text-capitalize">{{ str_replace('_', ' ', $payment->payment_method) }} ({{ $payment->reference_number ?? 'N/A' }})</span>
                            </div>
                        </div>

                        <div class="d-flex justify-content-between">
                            <div style="width: 200px;">
                                <div class="border-bottom text-center mb-2" style="height: 40px;"></div>
                                <p class="text-center small text-muted mb-0">Signature & Stamp</p>
                            </div>
                            <div class="text-end">
                                <p class="small text-muted mb-0">Served by: {{ $payment->recorder->name }}</p>
                                <p class="small text-muted mb-0">Issued at: {{ date('H:i:s') }}</p>
                            </div>
                        </div>
                    </div>

                    <div class="p-3 bg-dark text-white text-center">
                        <small>This is a valid legal receipt for school fees paid. Keep it safe.</small>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
@media print {
    .sidebar, .top-navbar, .footer-minimal, .d-print-none {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .receipt-container {
        margin-top: 0 !important;
    }
    .col-md-7 {
        width: 100% !important;
    }
    .card {
        box-shadow: none !important;
        border: 2px solid #000 !important;
    }
}
.receipt-card {
    border-top: 5px solid #0d6efd !important;
}
.uppercase { text-transform: uppercase; letter-spacing: 1px; }
</style>
@endsection
