from allauth.account.forms import SignupForm
from django import forms
from .models import *
import os
from django.contrib.auth.models import User

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class MyCustomSignupForm(SignupForm):
    def __init__(self, *args, **kwargs):
        super(MyCustomSignupForm, self).__init__(*args, **kwargs)
        self.fields['isdistributor'] = forms.BooleanField(required=False)
        
    def save(self, request):
        isdistributor = self.cleaned_data.pop('isdistributor', False)
        user = super(MyCustomSignupForm, self).save(request)
        try:
            res_temp, _ = Profile.objects.get_or_create(user=user)
            if isdistributor and not RequestForDistributor.objects.filter(user_profile=res_temp).exists():
                RequestForDistributor.objects.create(user_profile=res_temp)
        except Exception as e:
            print("Error in SignupForm save:", e)
        return user

class ContactForm(forms.Form):

    fullName = forms.CharField(label='Full Name',max_length=100)                       
    phone_number=forms.CharField(max_length=15)
    email = forms.EmailField(max_length=100)
    message = forms.CharField(widget=forms.Textarea)