@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">Mettre à jour ma formation</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>
                <h2 class="d-flex justify-content-center align-items-center vh-10">Ajoutez un diplôme ou certificat</h2>
                <div class="row d-flex justify-content-center align-items-center vh-10">
                
                    <div class="col-md-6">
                    
        @if(session('success'))
            <div class="alert alert-success">{{ session('success') }}</div>
        @endif

        <form action="{{ route('update', $degree->id) }}" method="POST" enctype="multipart/form-data">
        @csrf
       @method('PUT')
        <div class="mb-3">
            <label for="name" class="form-label">Nom de la formation</label>
            <input type="text" name="name" id="name" class="form-control" value="{{ old('name', $degree->name) }}" required>
        </div>

        <div class="mb-3">
            <label for="school_name" class="form-label">Nom de l'école ou du centre de formation</label>
            <input type="text" name="school_name" id="school_name" class="form-control"value="{{ old('school_name', $degree->school_name) }}">
        </div>

        <div class="mb-3">
            <label for="domain" class="form-label">Domaine</label>
            <input type="text" name="domain" id="domain" class="form-control" value="{{ old('domain', $degree->domain) }}"required>
        </div>

        <div class="mb-3">
            <label for="description" class="form-label">Description</label>
            <input type="text" name="description" id="description" class="form-control"value="{{ old('description', $degree->description) }}">
        </div>
        <div class="mb-3">
            <label for="lien" class="form-label">Media (lien de votre document)</label>
            <input type="text" name="lien" id="lien" class="form-control"value="{{ old('lien', $degree->lien) }}">
            @if ($errors->has('website'))
    <div class="alert alert-danger">
        {{ $errors->first('website') }}
    </div>
@endif
        </div>
        <div class="mb-3">
            <label for="media" class="form-label">Ajouter un Média</label>
            <input type="file" name="media" id="media" class="form-control">
            @if ($degree->media_path)
            <p>Fichier actuel : 
                <a href="{{ asset('storage/' . $degree->media_path) }}" target="_blank">
                    Télécharger ou visualiser le fichier actuel
                </a>
            </p>
        @else
            <p>Vous n'avez pas encore ajouté de média.</p>
        @endif
        </div>
        <div class="mb-3">
            <label for="type" class="form-label">Type</label>
            <select class="form-control" id="type" name="type"value="{{ old('type', $degree->type) }}" required>
                <option value="Diplome">Diplome</option>
                <option value="Certificat">Certificat</option>
            </select>
        </div>

        <div class="mb-3">
            <label for="start_date" class="form-label">Date de début</label>
            <input type="date" name="start_date" id="start_date" class="form-control" value="{{ old('start_date', $degree->start_date) }}"required>
        </div>
        <div class="mb-3">
            <label for="end_date" class="form-label">Date de fin</label>
            <input type="date" name="end_date" id="end_date" class="form-control" value="{{ old('end_date', $degree->end_date) }}" required>
        </div>


        <button type="submit" class="btn btn-primary">Mettre à jour</button>
    </form>
            </div>
        </div>
    </div>
</section>
    
@endsection