@extends('layouts.app')

@section('title', 'Student Profile - ' . $student->full_name)
@section('page_header', 'Student Intern Profile')

@section('content')
<div class="max-w-4xl mx-auto space-y-6">

    <!-- Profile Header Card -->
    <div class="bg-white p-8 rounded-3xl border border-slate-200/80 shadow-sm flex flex-col md:flex-row items-start md:items-center justify-between gap-6">
        <div class="flex items-center gap-5">
            <div class="w-16 h-16 rounded-2xl bg-gradient-to-tr from-emerald-600 to-teal-400 text-white font-extrabold flex items-center justify-center text-2xl shadow-xl shadow-emerald-600/30 flex-shrink-0">
                {{ strtoupper(substr($student->full_name, 0, 1)) }}
            </div>
            <div>
                <h2 class="text-2xl font-extrabold text-slate-900 tracking-tight">{{ $student->full_name }}</h2>
                <p class="text-sm font-semibold text-emerald-700">{{ $student->college->name ?? 'Direct Applicant / Independent' }}</p>
                <span class="text-xs text-slate-400">Student ID: #{{ $student->id }} • Added {{ $student->created_at->format('d M Y') }}</span>
            </div>
        </div>

        <div class="flex items-center gap-3 w-full md:w-auto">
            <a href="{{ route('admin.certificates.create', ['student_id' => $student->id]) }}" 
               class="flex-1 md:flex-none inline-flex items-center justify-center gap-2 bg-emerald-600 hover:bg-emerald-700 text-white font-bold text-xs px-5 py-3 rounded-xl shadow-lg shadow-emerald-600/20">
                <i data-lucide="award" class="w-4 h-4"></i>
                <span>Issue Certificate</span>
            </a>

            <a href="{{ route('admin.students.edit', $student->id) }}" 
               class="inline-flex items-center justify-center p-3 rounded-xl border border-slate-200 text-slate-700 hover:bg-slate-100">
                <i data-lucide="edit-3" class="w-4 h-4"></i>
            </a>
        </div>
    </div>

    <!-- Student Metadata Details Grid -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
        
        <div class="bg-white p-6 rounded-3xl border border-slate-200/80 shadow-sm space-y-4">
            <h3 class="text-xs font-extrabold text-slate-400 uppercase tracking-wider border-b border-slate-100 pb-2">Contact Details</h3>
            
            <div>
                <span class="block text-[11px] text-slate-400 uppercase font-semibold">Email</span>
                <p class="text-sm font-bold text-slate-800">{{ $student->email ?? 'Not provided' }}</p>
            </div>

            <div>
                <span class="block text-[11px] text-slate-400 uppercase font-semibold">Phone</span>
                <p class="text-sm font-bold text-slate-800">{{ $student->phone ?? 'Not provided' }}</p>
            </div>
        </div>

        <div class="bg-white p-6 rounded-3xl border border-slate-200/80 shadow-sm space-y-4">
            <h3 class="text-xs font-extrabold text-slate-400 uppercase tracking-wider border-b border-slate-100 pb-2">Demographics</h3>
            
            <div>
                <span class="block text-[11px] text-slate-400 uppercase font-semibold">Age / DOB</span>
                <p class="text-sm font-bold text-slate-800">{{ $student->age ? $student->age . ' Years' : 'N/A' }} {{ $student->dob ? '(' . date('d M Y', strtotime($student->dob)) . ')' : '' }}</p>
            </div>

            <div>
                <span class="block text-[11px] text-slate-400 uppercase font-semibold">Gender</span>
                <p class="text-sm font-bold text-slate-800">{{ $student->gender ?? 'N/A' }}</p>
            </div>
        </div>

        <div class="bg-white p-6 rounded-3xl border border-slate-200/80 shadow-sm space-y-4">
            <h3 class="text-xs font-extrabold text-slate-400 uppercase tracking-wider border-b border-slate-100 pb-2">College Information</h3>
            
            <div>
                <span class="block text-[11px] text-slate-400 uppercase font-semibold">Institution Name</span>
                <p class="text-sm font-bold text-slate-800">{{ $student->college->name ?? 'N/A' }}</p>
            </div>

            <div>
                <span class="block text-[11px] text-slate-400 uppercase font-semibold">Location</span>
                <p class="text-sm font-bold text-slate-800">{{ $student->college->city_state ?? 'N/A' }}</p>
            </div>
        </div>
    </div>

    <!-- Certificates Issued to Student List -->
    <div class="bg-white p-8 rounded-3xl border border-slate-200/80 shadow-sm space-y-6">
        <div class="flex items-center justify-between border-b border-slate-100 pb-4">
            <div>
                <h3 class="text-lg font-bold text-slate-900">Issued Certificates</h3>
                <p class="text-xs text-slate-500">History of certificates issued to {{ $student->full_name }}</p>
            </div>

            <a href="{{ route('admin.certificates.create', ['student_id' => $student->id]) }}" 
               class="text-xs font-bold text-emerald-600 hover:text-emerald-800 flex items-center gap-1">
                <i data-lucide="plus" class="w-4 h-4"></i>
                <span>Issue New Certificate</span>
            </a>
        </div>

        <div class="space-y-4">
            @forelse($student->certificates as $cert)
            <div class="flex flex-col sm:flex-row items-start sm:items-center justify-between p-5 rounded-2xl bg-slate-50 border border-slate-200 gap-4 hover:border-emerald-300 transition-all">
                <div class="space-y-1">
                    <div class="flex items-center gap-3">
                        <span class="font-mono text-sm font-extrabold text-emerald-700 bg-emerald-100/80 px-2.5 py-0.5 rounded border border-emerald-200">
                            {{ $cert->certificate_uuid }}
                        </span>
                        @if($cert->status === 'active')
                            <span class="text-[10px] font-bold text-emerald-700 bg-emerald-100 px-2 py-0.5 rounded-full">Active</span>
                        @else
                            <span class="text-[10px] font-bold text-rose-700 bg-rose-100 px-2 py-0.5 rounded-full">Revoked</span>
                        @endif
                    </div>
                    <h4 class="text-sm font-bold text-slate-900">{{ $cert->course->title ?? 'Internship Certificate' }}</h4>
                    <p class="text-xs text-slate-500">
                        Duration: {{ $cert->duration }} ({{ date('d M Y', strtotime($cert->start_date)) }} — {{ date('d M Y', strtotime($cert->end_date)) }})
                    </p>
                </div>

                <div class="flex items-center gap-2 self-end sm:self-center">
                    <a href="{{ route('admin.certificates.show', $cert->id) }}" 
                       class="px-4 py-2 bg-white hover:bg-slate-100 text-slate-700 text-xs font-bold rounded-xl border border-slate-200 transition-colors">
                        View Details
                    </a>

                    <a href="{{ route('admin.certificates.download_pdf', $cert->id) }}" 
                       class="p-2 text-emerald-600 hover:bg-emerald-100 bg-emerald-50 rounded-xl transition-colors" title="Download PDF">
                        <i data-lucide="download" class="w-4 h-4"></i>
                    </a>
                </div>
            </div>
            @empty
            <div class="text-center py-8 text-slate-400 text-xs">
                No certificates generated for this student yet.
            </div>
            @endforelse
        </div>
    </div>

</div>
@endsection
