from django.shortcuts import render, redirect
from django.contrib import messages
from .forms import ContactForm, CandidatureForm

# Create your views here.

def home(request):
    return render(request, "pages/home.html")

def a_propos(request):
    return render(request, 'pages/a_propos.html')

def blog(request):
    return render(request, 'pages/blog.html')

def vie_etudiante(request):
    return render(request, 'pages/vie_etudiante.html')

def formations(request):
    return render(request, "pages/formations.html")

def postuler(request):
    if request.method == 'POST':
        form = CandidatureForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            messages.success(request, "Votre candidature a été soumise avec succès ! Nous l'étudierons prochainement.")
            return redirect('postuler')
        else:
            messages.error(request, "Une erreur est survenue dans le formulaire. Veuillez vérifier vos informations.")
    else:
        form = CandidatureForm()
    
    return render(request, 'pages/postuler.html', {'form': form})

def classe_preparatoire(request):
    return render(request, 'formations/classe_prepa.html')

def licence(request):
    return render(request, "formations/licence.html")

def licence_soir(request):
    return render(request, "formations/licence-cour-du-soir.html")

def bts(request):
    return render(request, "formations/bts.html")

def classe_prepa(request):
    return render(request, "formations/classe_prepa.html")

def master(request):
    return render(request, "formations/master.html")


def licence_energie_renouvelable(request):
    return render(request, 'formations/specifique/licence/energie_renouvelable.html')

def licence_systemes_reseaux(request):
    return render(request, 'formations/specifique/licence/systemes_reseaux.html')

def licence_developpement_applications(request):
    return render(request, 'formations/specifique/licence/developpement_applications.html')

def licence_securite_informatique(request):
    return render(request, 'formations/specifique/licence/securite_informatique.html')

def licence_electrotechnique(request):
    return render(request, 'formations/specifique/licence/electrotechnique.html')

def licence_genie_electrique(request):
    return render(request, 'formations/specifique/licence/genie_electrique.html')




#Niveau master

def master_genie_energie(request):
    return render(request, 'formations/specifique/master/genie_energie.html')


def master_systeme_logiciel(request):
    return render(request, 'formations/specifique/master/systeme_logiciel.html')

def master_banque_finance(request):
    return render(request, 'formations/specifique/master/banque_finance.html')

def master_comptabilite_audit(request):
    return render(request, 'formations/specifique/master/comptabilite_audit.html')


def master_gestion_projets(request):
    return render(request, 'formations/specifique/master/gestion_projets.html')


def master_ressources_humaines(request):
    return render(request, 'formations/specifique/master/ressources_humaines.html')

def master_collectivites_locales(request):
    return render(request, 'formations/specifique/master/collectivites_locales.html')

def master_management_international(request):
    return render(request, 'formations/specifique/master/management_international.html')

def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, "Votre message a été envoyé avec succès ! Nous vous répondrons dès que possible.")
            return redirect('contact')
        else:
            messages.error(request, "Une erreur est survenue. Veuillez vérifier les informations saisies.")
    else:
        form = ContactForm()
    
    return render(request, 'pages/contact.html', {'form': form})

#bts

def bts_developpeur_applications(request):
    return render(request, 'formations/specifique/bts/developpeur_applications.html')

def bts_telecommunications(request):
    return render(request, 'formations/specifique/bts/telecommunications.html')

def bts_reseaux_locaux(request):
    return render(request, 'formations/specifique/bts/reseaux_locaux.html')

def bts_maintenance_informatique(request):
    return render(request, 'formations/specifique/bts/maintenance_informatique.html')

def bts_electrotechnique(request):
    return render(request, 'formations/specifique/bts/electrotechnique.html')

def bts_energie_thermique(request):
    return render(request, 'formations/specifique/bts/energie_thermique.html')

def bts_comptabilite_gestion(request):
    return render(request, 'formations/specifique/bts/comptabilite_gestion.html')

def bts_commerce_international(request):
    return render(request, 'formations/specifique/bts/commerce_international.html')

def bts_finances_banque(request):
    return render(request, 'formations/specifique/bts/finances_banque.html')

def bts_collectivites_locales(request):
    return render(request, 'formations/specifique/bts/collectivites_locales.html')



# classe preparatoire

# Les pages spécifiques de prépa ont été supprimées, ne restent que les cycles principaux.

def cycle_gestion(request):
    return render(
        request,
        'formations/specifique/classe_preparatoire/cycle_eco_gestion/cycle_gestion.html'
    )


def cycle_ingenieurs(request):
    return render(
        request,
        'formations/specifique/classe_preparatoire/cycle_ingenieurs/cycle_ingenieurs.html'
    )