from django import forms
from django.contrib.auth.forms import UserCreationForm
# from django.contrib.auth.models import User
from django.contrib.auth import get_user_model

class RegistrationForm(UserCreationForm):
    # phone = forms.CharField(label='Phone')

    first_name = forms.CharField(widget=forms.TextInput(attrs={'autofocus': True}))
    class Meta:
        # model = User
        model = get_user_model()
        fields = ['first_name', 'last_name', 'phone', 'email', 'password1', 'password2']
    
    def save(self, commit=True):
        user = super().save(commit=False)
        if not user.email:
            user.email = self.cleaned_data['phone']  # Use phone as default email
        if commit:
            user.save()
        return user