
from django import forms
from .models import ContactMessage, Candidature

class ContactForm(forms.ModelForm):
    class Meta:
        model = ContactMessage
        fields = ['nom', 'email', 'telephone', 'objet', 'message']
        widgets = {
            'nom': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Votre nom complet'}),
            'email': forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'votre@email.com'}),
            'telephone': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '+228 XX XX XX XX'}),
            'objet': forms.Select(attrs={'class': 'form-select'}),
            'message': forms.Textarea(attrs={'class': 'form-control', 'rows': 5, 'placeholder': 'Votre message...'}),
        }

class CandidatureForm(forms.ModelForm):
    class Meta:
        model = Candidature
        fields = '__all__'
        exclude = ['date_soumission']
        widgets = {
            'date_naissance': forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
            'photo_identite': forms.FileInput(attrs={'class': 'form-control'}),
            'bac_releve': forms.FileInput(attrs={'class': 'form-control'}),
            'acte_naissance': forms.FileInput(attrs={'class': 'form-control'}),
            'certificat_nationalite': forms.FileInput(attrs={'class': 'form-control'}),
            'cv': forms.FileInput(attrs={'class': 'form-control'}),
            'lettre_motivation': forms.FileInput(attrs={'class': 'form-control'}),
            'adresse_complete': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
            'motivation': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
            'experience_professionnelle': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
            'projet_professionnel': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
        }
        # Add form-control class to all fields
    
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            if 'class' not in field.widget.attrs:
                field.widget.attrs['class'] = 'form-control'
            if isinstance(field.widget, forms.Select):
                field.widget.attrs['class'] = 'form-select'
            if isinstance(field.widget, forms.CheckboxInput):
                field.widget.attrs['class'] = 'form-check-input'
