@extends('layouts.base')

@section('menu')
    @include('etudiants.menu')
@endsection

@section('content')
<section class="profile-details bg-light py-5">
    <div class="container">
        <!-- Header -->
        <div class="header d-flex justify-content-between align-items-center mb-4">
            <h1 class="text-primary">Mon Profil</h1>
            <a href="{{ route('etudiants.offres.index') }}" class="btn btn-outline-primary">
                <i class="bi bi-arrow-left"></i> Retour à l'accueil
            </a>
        </div>

        <!-- User Profile Details -->
        <div class="card shadow-sm">
            <div class="card-body">
                <div class="d-flex align-items-center mb-4">
                    <img src="{{ asset('auth/images/img2.svg') }}" alt="User Avatar" class="rounded-circle me-3" width="80" height="80">
                    <div>
                        <h3 class="card-title">{{ auth()->user()->name }} {{ auth()->user()->surname }}</h3>
                        <p class="text-muted">{{ auth()->user()->email }}</p>
                    </div>
                </div>

                <hr>

                <div class="row">
                    <div class="col-md-6">
                        <h5>Date de naissance</h5>
                        <p>{{ auth()->user()->birthday ? (new \DateTime(auth()->user()->birthday))->format('d/m/Y') : 'Non spécifiée' }}</p>
                    </div>
                    <div class="col-md-6">
                        <h5>Lieu de naissance</h5>
                        <p>{{ auth()->user()->birthplace ?: 'Non spécifié' }}</p>
                    </div>
                    <div class="col-md-6">
                        <h5>Téléphone</h5>
                        <p>{{ auth()->user()->phone ?: 'Non spécifié' }}</p>
                    </div>
                    <div class="col-md-6">
                        <h5>Matricule</h5>
                        <p>{{ auth()->user()->matricule ?: 'Non spécifié' }}</p>
                    </div>
                    <div class="col-md-6">
                        <h5>Adresse</h5>
                        <p>{{ auth()->user()->address ?: 'Non spécifiée' }}</p>
                    </div>
                    <div class="col-md-6">
                    @if($user->cv)
                                <!-- Affichage de l'image -->
                                @if(in_array(pathinfo($user->cv, PATHINFO_EXTENSION), ['jpg', 'jpeg', 'png', 'gif']))
                                <h5>Curiculum Vitae</h5>
                                    <a href="{{ Storage::url($user->cv) }}" download class="btn btn-primary btn-sm mt-2">
                                        <i class="fa fa-download"></i> Télécharger le cv
                                    </a>
                                @endif
                                
                                <!-- Affichage du PDF -->
                                @if(pathinfo($user->cv, PATHINFO_EXTENSION) == 'pdf')
                                <h5>Curiculum Vitae</h5>
                                    <a href="{{ Storage::url($user->cv) }}" download class="btn btn-primary btn-sm mt-2">
                                        <i class="fa fa-download"></i> Télécharger le cv
                                    </a>
                                @endif
                                
                                <!-- Message pour les autres types de fichiers -->
                                @if(in_array(pathinfo($user->cv, PATHINFO_EXTENSION), ['docx', 'xlsx', 'pptx']))
                                <h5>Curiculum Vitae</h5>
                                    <a href="{{ Storage::url($user->cv) }}" download class="btn btn-primary btn-sm mt-2">
                                        <i class="fa fa-download"></i> Télécharger le cv
                                    </a>
                                @endif
                            @else
                                <p>Aucune pièce jointe</p>
                            @endif
                            </div>
                </div>

                <hr>

                <!-- Actions -->
                <div class="d-flex justify-content-center mt-3">
                    <a href="{{ route('etudiants.editProfile') }}" class="btn btn-primary mx-2">
                        Modifier le profil
                    </a>
                    <a href="{{ route('alumnis.createDegree') }}" class="btn btn-primary mx-2">
                        Ajouter un diplôme/certificat
                    </a>
                    </a>
                    <a href="{{ route('alumnis.degree') }}" class="btn btn-primary mx-2">
                        Voir mes formations
                    </a>
                    <a href="{{ route('logout') }}" class="btn btn-outline-danger mx-2">
                        <i class="bi bi-box-arrow-right"></i> Déconnexion
                    </a>
                </div>
            </div>
        </div>
    </div>
</section>
@endsection
