{{-- Mentorship Public Applications View --}}
{{-- List of applications for verified email --}}

<x-site-layout 
    title="Your Applications"
    meta-description="View all your mentorship programme applications"
    :show-breadcrumbs="true">

    {{-- Hero Section — Advocacy Style --}}
    <div class="relative bg-gradient-to-r from-green-700 to-emerald-800 shadow-xl">
        <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
            <div class="text-center">
                <span class="inline-block px-4 py-1 bg-white/20 text-white rounded-full text-sm font-semibold mb-4">
                    <i class="fas fa-clipboard-list mr-2"></i> My Applications
                </span>
                <h1 class="text-4xl md:text-5xl font-serif font-bold text-white mb-4">Your Applications</h1>
                <p class="text-xl text-green-100 max-w-3xl mx-auto">
                    View and track all your mentorship programme applications
                </p>
            </div>
        </div>
    </div>

    {{-- Breadcrumb --}}
    <div class="bg-gray-50 border-b border-gray-200">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3">
            <nav class="flex items-center space-x-2 text-sm text-gray-600" aria-label="Breadcrumb">
                <a href="{{ url('/') }}" class="hover:text-green-600 transition flex items-center">
                    <i class="fas fa-home mr-1"></i>Home
                </a>
                <i class="fas fa-chevron-right text-gray-400 text-xs"></i>
                <a href="{{ route('mentorship.public.index') }}" class="hover:text-green-600 transition">Mentorship</a>
                <i class="fas fa-chevron-right text-gray-400 text-xs"></i>
                <span class="text-gray-900 font-medium">Your Applications</span>
            </nav>
        </div>
    </div>

    {{-- Main Content Area --}}
    <div class="py-12 bg-gray-50">
        <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
            
            {{-- Flash Messages --}}
            @if(session('success'))
                <div class="mb-6 p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg">
                    <i class="fas fa-check-circle mr-2"></i>
                    {{ session('success') }}
                </div>
            @endif

            @if(session('error'))
                <div class="mb-6 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg">
                    <i class="fas fa-exclamation-circle mr-2"></i>
                    {{ session('error') }}
                </div>
            @endif

            {{-- Applications List --}}
            @if($applications->count() > 0)
                <div class="space-y-4">
                    @foreach($applications as $application)
                        <div class="bg-white rounded-lg shadow-sm hover:shadow-md transition overflow-hidden border border-gray-100">
                            <div class="p-6">
                                <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
                                    {{-- Application Info --}}
                                    <div class="flex items-start gap-4">
                                        <div class="w-12 h-12 rounded-full @if($application->isApproved()) bg-green-100 @elseif($application->isRejected()) bg-red-100 @else bg-yellow-100 @endif flex items-center justify-center flex-shrink-0">
                                            @if($application->isApproved())
                                                <i class="fas fa-check text-green-600"></i>
                                            @elseif($application->isRejected())
                                                <i class="fas fa-times text-red-600"></i>
                                            @else
                                                <i class="fas fa-clock text-yellow-600"></i>
                                            @endif
                                        </div>
                                        <div>
                                            <h3 class="text-lg font-semibold text-gray-900">
                                                {{ $application->programme->title ?? 'Mentorship Programme' }}
                                            </h3>
                                            <p class="text-sm text-gray-600 mt-1">
                                                <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium 
                                                    {{ $application->role_preference === 'mentor' ? 'bg-blue-100 text-blue-800' : 'bg-purple-100 text-purple-800' }}">
                                                    {{ ucfirst($application->role_preference) }}
                                                </span>
                                                <span class="mx-2">•</span>
                                                Applied {{ $application->created_at->format('M d, Y') }}
                                            </p>
                                            @if($application->payment_required)
                                                <p class="text-xs text-gray-500 mt-1">
                                                    <i class="fas fa-credit-card mr-1"></i>
                                                    Payment: 
                                                    @if($application->payment_status === 'paid')
                                                        <span class="text-green-600 font-medium">Paid</span>
                                                    @elseif($application->payment_status === 'pending')
                                                        <span class="text-yellow-600 font-medium">Pending</span>
                                                    @else
                                                        <span class="text-red-600 font-medium">Unpaid</span>
                                                    @endif
                                                </p>
                                            @endif
                                        </div>
                                    </div>

                                    {{-- Status & Actions --}}
                                    <div class="flex items-center gap-4">
                                        @php
                                            $statusColors = [
                                                'pending' => 'bg-yellow-100 text-yellow-800',
                                                'under_review' => 'bg-blue-100 text-blue-800',
                                                'approved' => 'bg-green-100 text-green-800',
                                                'rejected' => 'bg-red-100 text-red-800',
                                                'payment_pending' => 'bg-purple-100 text-purple-800',
                                                'waitlisted' => 'bg-orange-100 text-orange-800',
                                            ];
                                        @endphp
                                        <span class="px-3 py-1 rounded-full text-sm font-medium {{ $statusColors[$application->status] ?? 'bg-gray-100 text-gray-800' }}">
                                            {{ $application->status_label }}
                                        </span>
                                        <a href="{{ route('mentorship.public.status', $application) }}" 
                                           class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition text-sm">
                                            <i class="fas fa-eye mr-1"></i>
                                            View Details
                                        </a>
                                    </div>
                                </div>

                                {{-- Rejection Reason --}}
                                @if($application->isRejected() && $application->rejection_reason)
                                    <div class="mt-4 pt-4 border-t border-gray-100">
                                        <p class="text-sm text-red-600">
                                            <i class="fas fa-info-circle mr-1"></i>
                                            <strong>Reason:</strong> {{ $application->rejection_reason }}
                                        </p>
                                    </div>
                                @endif

                                {{-- Payment Action --}}
                                @if($application->payment_required && $application->payment_status !== 'paid')
                                    <div class="mt-4 pt-4 border-t border-gray-100">
                                        <div class="flex items-center justify-between">
                                            <p class="text-sm text-gray-600">
                                                <i class="fas fa-exclamation-triangle text-yellow-500 mr-1"></i>
                                                Payment of {{ $application->formatted_payment_amount }} required
                                            </p>
                                            <a href="{{ route('mentorship.payments.create', ['application_id' => $application->id]) }}" 
                                               class="px-4 py-2 bg-yellow-500 text-white rounded-lg hover:bg-yellow-600 transition text-sm">
                                                <i class="fas fa-credit-card mr-1"></i>
                                                Pay Now
                                            </a>
                                        </div>
                                    </div>
                                @endif
                            </div>
                        </div>
                    @endforeach
                </div>

                {{-- Pagination --}}
                @if(method_exists($applications, 'hasPages') && $applications->hasPages())
                    <div class="mt-8">
                        {{ $applications->links() }}
                    </div>
                @endif
            @else
                {{-- Empty State --}}
                <div class="bg-white rounded-lg shadow-sm">
                    <div class="p-12 text-center">
                        <div class="w-20 h-20 mx-auto mb-6 bg-gray-100 rounded-full flex items-center justify-center">
                            <i class="fas fa-folder-open text-gray-300 text-3xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-900 mb-2">No Applications Found</h3>
                        <p class="text-gray-500 mb-6 max-w-md mx-auto">
                            You haven't submitted any applications yet. Browse our mentorship programmes and apply today!
                        </p>
                        <a href="{{ route('mentorship.public.index') }}" 
                           class="inline-flex items-center px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition">
                            <i class="fas fa-graduation-cap mr-2"></i>
                            Browse Programmes
                        </a>
                    </div>
                </div>
            @endif

            {{-- Summary Stats --}}
            @if($applications->count() > 0)
                <div class="mt-8 grid grid-cols-2 md:grid-cols-4 gap-4">
                    <div class="bg-white rounded-lg p-4 text-center shadow-sm">
                        <div class="text-2xl font-bold text-gray-900">{{ $applications->count() }}</div>
                        <div class="text-sm text-gray-500">Total Applications</div>
                    </div>
                    <div class="bg-white rounded-lg p-4 text-center shadow-sm">
                        <div class="text-2xl font-bold text-green-600">{{ $applications->where('status', 'approved')->count() }}</div>
                        <div class="text-sm text-gray-500">Approved</div>
                    </div>
                    <div class="bg-white rounded-lg p-4 text-center shadow-sm">
                        <div class="text-2xl font-bold text-yellow-600">{{ $applications->whereIn('status', ['pending', 'under_review'])->count() }}</div>
                        <div class="text-sm text-gray-500">Pending</div>
                    </div>
                    <div class="bg-white rounded-lg p-4 text-center shadow-sm">
                        <div class="text-2xl font-bold text-red-600">{{ $applications->where('status', 'rejected')->count() }}</div>
                        <div class="text-sm text-gray-500">Rejected</div>
                    </div>
                </div>
            @endif

            {{-- Quick Links --}}
            <div class="mt-8 text-center">
                <a href="{{ route('mentorship.public.index') }}#programmes" 
                   class="inline-flex items-center px-6 py-3 border-2 border-green-600 text-green-600 rounded-lg hover:bg-green-50 transition">
                    <i class="fas fa-plus mr-2"></i>
                    Submit New Application
                </a>
            </div>
        </div>
    </div>
</x-site-layout>
