from django import forms
from django.contrib.auth.forms import UserCreationForm
from web.models.custom_user import CustomUser
from markdownx.fields import MarkdownxFormField
from captcha.fields import CaptchaField


class SignupForm(UserCreationForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['email'].required = True
        self.fields['email'].help_text = 'Email will be used to alert you of major announcements or information regarding your account.'
        ignored_help_text_fields = ['password1', 'password2', 'username']
        for field_name in ignored_help_text_fields:
            self.fields[field_name].help_text = ''

    url = forms.URLField(max_length=200, required=True, help_text='The URL of the website that you intend to add the widget to. please follow the format of: https://your-website.com')
    description = forms.CharField(widget=forms.Textarea, help_text='Please provide a description about your website. Feel free to add a description about yourself as well.')

    rule_conf = forms.BooleanField(label='Have you read the rules?', help_text='Please be sure to read the rules before signing up for this webring. The rules can be found <a href="https://christian-webring.nekoweb.org/rules.html" target="_blank">here</a>')
    rule_conf.widget.attrs.update({'class': 'checkmark'})

    email_only = forms.BooleanField(label='Skip Member Area', help_text='If you just want to add the webring widget to your website and do not care about the community aspect of this webring, click this checkmark. Any important announcements will be sent to you via email. If you decide you would like to join the member area later on, contact an admin.', required=False)
    email_only.widget.attrs.update({'class': 'checkmark'})

    comments = forms.CharField(widget=forms.Textarea, required=False)
    captcha = CaptchaField()

    class Meta:
        model = CustomUser
        fields = (
            'username',
            'email',
            'password1',
            'password2',
            'url',
            'description',
            'rule_conf',
            'email_only',
            'comments'
        )


class EditProfileForm(forms.Form):
    avatar = forms.ImageField(allow_empty_file=True, required=False)
    url = forms.URLField(max_length=200, help_text='Required')
    description = forms.CharField(widget=forms.Textarea)
    

class ThreadPostForm(forms.Form):
    content = MarkdownxFormField()

    class Meta:
        fields = ('content')

