from django import forms
from exposant.models import Exposant, Categorie
from administration.models import pub_video


class ExposantForm(forms.ModelForm):
    class Meta:
        model = Exposant
        fields = ['nom_exposant', 'stand', 'allee', 'adresse', 'code_postal', 
                 'ville', 'annee_exposant', 'num_tel', 'email', 'site_web', 'categorie']
        widgets = {
            'nom_exposant': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'stand': forms.NumberInput(attrs={'class': 'expo-form-input'}),
            'allee': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'adresse': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'code_postal': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'ville': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'annee_exposant': forms.NumberInput(attrs={'class': 'expo-form-input'}),
            'num_tel': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'email': forms.EmailInput(attrs={'class': 'expo-form-input'}),
            'site_web': forms.URLInput(attrs={'class': 'expo-form-input'}),
            'categorie': forms.Select(attrs={'class': 'expo-form-select'}),
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Filtrer les catégories pour n'afficher que celles qui sont actives
        self.fields['categorie'].queryset = Categorie.objects.filter(is_actif=True).order_by('nom_categorie')
        
        # Optionnel: ajouter un message d'aide
        self.fields['categorie'].help_text = "Seules les catégories actives sont affichées"


class VideoPartenaireForm(forms.ModelForm):
    class Meta:
        model = pub_video
        fields = ['nom_societe', 'nom_collecteurs', 'ecran_podium', 'ecran_gastronomie', 
                 'annee_video', 'annee_affichage', 'is_owned']
        widgets = {
            'nom_societe': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'nom_collecteurs': forms.TextInput(attrs={'class': 'expo-form-input'}),
            'ecran_podium': forms.CheckboxInput(attrs={'class': 'expo-form-check-input'}),
            'ecran_gastronomie': forms.CheckboxInput(attrs={'class': 'expo-form-check-input'}),
            'annee_video': forms.NumberInput(attrs={'class': 'expo-form-input'}),
            'annee_affichage': forms.NumberInput(attrs={'class': 'expo-form-input'}),
            'is_owned': forms.CheckboxInput(attrs={'class': 'expo-form-check-input'}),
        }


class ImportExcelForm(forms.Form):
    fichier_excel = forms.FileField(
        label="Sélectionnez un fichier Excel (.xlsx)",
        help_text="Les colonnes doivent être : Société, Collecteurs, Podium (oui/non), Gastro (oui/non), Année Vidéo, Année Affichage, Owned (oui/non)",
        widget=forms.FileInput(attrs={'class': 'expo-form-input', 'accept': '.xlsx'})
    )