from django import forms
from django.forms import ModelForm, CharField, SlugField
from django.core.validators import validate_unicode_slug

from .models import Network, Host, Channel, Owner, CurseWord, CurseAdjective

class NetworkForm(ModelForm):
    class Meta:
        model=Network
        #fields = ['name', 'slug', 'nickname', 'password', 'username', 'home_channel', 'command_character', 'help_character']
        fields='__all__'
        #exclude = ['slug'] #Does not need "fields = '__all__'".
        labels={
            'name': '<i class="sitemap icon"></i>Name',
            'slug': '<i class="linkify icon"></i>Slug',
            'nickname': '<i class="id badge icon"></i>Nickname',
            'username': '<i class="id card icon"></i>Username',
            'password': '<i class="privacy icon"></i>Password',
            'mail': '<i class="envelope icon"></i>NickServ registration E-mail',
            'home_channel': '<i class="hashtag icon"></i>Home channel',
            'command_character': '<i class="terminal icon"></i>Command character',
            'help_character': '<i class="help icon"></i>Help character',
            #'network_services': '<i class="lightbulb outline icon"></i>Network services',
            'enabled': '<i class="power off icon"></i>Enabled',
            # 'mute': '<i class="comment slash icon"></i>Mute',
        }
        widgets={
            'name': forms.TextInput(attrs={'autocomplete': 'on'}),
            'nickname': forms.TextInput(attrs={'autocomplete': 'on'}),
            'username': forms.TextInput(attrs={'autocomplete': 'on'}),
        }

class HostForm(ModelForm):
    class Meta:
        model=Host
        exclude=['network', 'connection_attempts', 'connection_succeeds']
        labels={
            'address': '<i class="server icon"></i>Address',
            'port': '<i class="dungeon icon"></i>Port',
            'ssl': '<i class="lock icon"></i>Use SSL',
        }
        widgets={
            'address': forms.TextInput(attrs={'autocomplete': 'on'}),
            'ssl': forms.CheckboxInput(attrs={'_style': 'toggle',}),
        }

class OwnerForm(ModelForm):
    class Meta:
        model=Owner
        fields='__all__'
        labels={
            'source': '<i class="fingerprint icon"></i>Owner host',
        }
        layout = [
            ('Two Fields',
                ('Field', 'source'),
                ('Field', 'DELETE'),
            )
        ]

class ChannelForm(ModelForm):
    class Meta:
        model=Channel
        fields=['autojoin', 'statistic_commands', 'games', 'chat']
        labels={
            'autojoin': '<i class="power icon"></i>Auto join',
            'statistic_commands': '<i class="chart pie icon"></i>Statistic commands',
            'chat': '<i class="gamepad icon"></i>Games',
            'games': '<i class="gamepad icon"></i>Games',
        }
        widgets={
            'autojoin': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
            'statistic_commands': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
            'chat': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
            'games': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
        }

class CurseWordForm(ModelForm):
    class Meta:
        model=CurseWord
        fields={'word'}
        labels={
            'word': '<i class="book dead icon"></i>Curse word'
        }
        widgets={
            'word': forms.TextInput(attrs={'_no_required': 'True'}),
        }

class CurseAdjectiveForm(ModelForm):
    class Meta:
        model=CurseAdjective
        fields={'word'}
        labels={
            'word': '<i class="book dead icon"></i>Adjective'
        }
        widgets={
            'word': forms.TextInput(attrs={'_no_required': 'True'}),
        }
