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)
        TITLE_CHOICES =( ("Mr", "Mr"), ("Ms", "Ms"), ) 
        self.fields['title'] = forms.ChoiceField(choices=TITLE_CHOICES,label="Title")
        self.fields['full_name'] = forms.CharField(max_length=100)
        self.fields['house_no'] = forms.CharField(max_length=100)
        self.fields['postcode'] = forms.CharField(max_length=100)
        self.fields['town'] = forms.CharField(max_length=100)
        self.fields['telephone_number'] = forms.CharField(max_length=100)
        HYH =( ("Online Banner", "Online Banner"), ("Social Media", "Social Media"),("Recommendation","Recommendation"),("Search Engines","Search Engine") ) 
        self.fields['how_you_hear_about_us'] = forms.ChoiceField(choices=HYH,label="How you hear about us ?")

        
        
    def save(self, request):
        
        title = self.cleaned_data.pop('title')
        house_no = self.cleaned_data.pop('house_no')
        postcode = self.cleaned_data.pop('postcode')
        town = self.cleaned_data.pop('town')
        telephone_number = self.cleaned_data.pop('telephone_number')
        full_name = self.cleaned_data.pop('full_name')

        how_you_hear_about_us = self.cleaned_data.pop('how_you_hear_about_us')

        user = super(MyCustomSignupForm, self).save(request)
        try:
            res_temp = UserProfile.objects.create(user=User.objects.get(id=user.id),title=title,house_no=house_no,postcode=postcode,town=town,telephone_number=telephone_number,howyouhear=how_you_hear_about_us,full_name=full_name)
            res_temp.save()
        except Exception as e:
            print(e)
        return user

 