from django import forms
from .models import Student, Assignment, COURSE_CHOICES, GENDER_CHOICES

from .models import PortfolioItem


class RegistrationForm(forms.ModelForm):
    password = forms.CharField(
        widget=forms.PasswordInput(attrs={'placeholder': 'Create a password for your student account'}),
        min_length=6,
        label='Password'
    )
    confirm_password = forms.CharField(
        widget=forms.PasswordInput(attrs={'placeholder': 'Confirm your password'}),
        label='Confirm Password'
    )

    class Meta:
        model = Student
        fields = ['full_name', 'email', 'phone_number', 'course', 'gender', 'has_prior_knowledge']
        widgets = {
            'full_name': forms.TextInput(attrs={'placeholder': 'Enter your full name'}),
            'email': forms.EmailInput(attrs={'placeholder': 'yourname@gmail.com'}),
            'phone_number': forms.TextInput(attrs={'placeholder': '080XXXXXXXX'}),
            'course': forms.Select(),
            'gender': forms.RadioSelect(),
            'has_prior_knowledge': forms.RadioSelect(choices=[(True, 'Yes'), (False, 'No')]),
        }
        labels = {
            'full_name': 'Full Name',
            'email': 'Gmail Address',
            'phone_number': 'Phone Number',
            'course': 'Preferred Course',
            'gender': 'Gender',
            'has_prior_knowledge': 'Do you have prior knowledge of this skill?',
        }

    def clean(self):
        cleaned_data = super().clean()
        password = cleaned_data.get('password')
        confirm_password = cleaned_data.get('confirm_password')
        if password and confirm_password and password != confirm_password:
            raise forms.ValidationError('Passwords do not match.')
        return cleaned_data


class AssignmentUploadForm(forms.ModelForm):
    class Meta:
        model = Assignment
        fields = ['title', 'description', 'file']
        widgets = {
            'title': forms.TextInput(attrs={'placeholder': 'Assignment title'}),
            'description': forms.Textarea(attrs={'rows': 3, 'placeholder': 'Brief description (optional)'}),
        }
        labels = {
            'title': 'Assignment Title',
            'description': 'Description',
            'file': 'Upload File',
        }


class LoginForm(forms.Form):
    email = forms.EmailField(
        widget=forms.EmailInput(attrs={'placeholder': 'yourname@gmail.com'}),
        label='Email Address'
    )
    password = forms.CharField(
        widget=forms.PasswordInput(attrs={'placeholder': 'Your password'}),
        label='Password'
    )



class PortfolioForm(forms.ModelForm):
    class Meta:
        model = PortfolioItem
        fields = ['title', 'category', 'image', 'description', 'instructor_name']
        widgets = {
            'title': forms.TextInput(attrs={
                'placeholder': 'Enter project title',
                'class': 'form-control'
            }),
            'description': forms.Textarea(attrs={
                'rows': 5,
                'placeholder': 'Describe this work...'
            }),
            'instructor_name': forms.TextInput(attrs={
                'placeholder': 'Instructor / Creator Name'
            }),
            'category': forms.Select(attrs={'class': 'form-control'}),
        }
        labels = {
            'image': 'Project Image',
            'instructor_name': 'Instructor Name',
        }