from ckeditor_uploader.widgets import CKEditorUploadingWidget
from django import forms
from django.forms.widgets import HiddenInput
from django.utils.translation import gettext_lazy as _

from tasks.models import Task, TaskList
from .models import TopicGroup, Topic, Attachment, Etherpad, FileUpload


class DateInput(forms.DateInput):
    input_type = "date"


class TopicGroupAdminForm(forms.ModelForm):
    class Meta:
        model = TopicGroup
        fields = "__all__"

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für Link"),
            "slug": _("Permalink"),
            "short_description": _("Kurzbeschreibung"),
        }

        help_texts = {
            "shortterm": _("max. 10 Zeichen erlaubt."),
        }


class TopicAdminForm(forms.ModelForm):
    class Meta:
        model = Topic
        fields = "__all__"

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für Link"),
            "slug": _("Permalink"),
            "task_list": _("Aufgabenbereich"),
            "description": _("Beschreibung"),
        }

        help_texts = {
            "shortterm": _("max. 10 Zeichen erlaubt."),
        }

        widgets = {"description": CKEditorUploadingWidget(config_name="default")}


class AttachmentAdminForm(forms.ModelForm):
    class Meta:
        model = Attachment
        fields = "__all__"

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für Link"),
            "slug": _("Permalink"),
            "description": _("Beschreibung"),
        }

        help_texts = {
            "shortterm": _("max. 10 Zeichen erlaubt."),
        }

        widgets = {"description": CKEditorUploadingWidget(config_name="default")}


class EtherpadAdminForm(forms.ModelForm):
    class Meta:
        model = Etherpad
        fields = [
            "title",
            "date",
            "attachment",
        ]


class FileUploadAdminForm(forms.ModelForm):
    class Meta:
        model = FileUpload
        fields = [
            "title",
            "file_field",
            "attachment",
        ]


class TopicInlineForm(forms.ModelForm):
    class Meta:
        model = Topic
        fields = [
            "title",
            "shortterm",
            "slug",
        ]

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für Link"),
            "slug": _("Permalink"),
        }


class AttachmentInlineForm(forms.ModelForm):
    class Meta:
        model = Attachment
        fields = [
            "title",
            "shortterm",
            "slug",
        ]

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für Link"),
            "slug": _("Permalink"),
        }


class EtherpadInlineForm(forms.ModelForm):
    class Meta:
        model = Etherpad
        fields = [
            "title",
            "date",
            "attachment",
        ]

        labels = {
            "title": _("Titel"),
            "date": _("Datum"),
        }


class FileUploadInlineForm(forms.ModelForm):
    class Meta:
        model = FileUpload
        fields = [
            "title",
            "file_field",
        ]

        labels = {
            "title": _("Titel"),
        }


class TopicCreateForm(forms.ModelForm):
    class Meta:
        model = Topic
        fields = [
            "title",
            "shortterm",
            "description",
            "topic_group",
        ]

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für den Link"),
            "description": _("Beschreibung"),
        }

        widgets = {
            "topic_group": HiddenInput,
        }


class TopicUpdateForm(forms.ModelForm):
    class Meta:
        model = Topic
        fields = [
            "title",
            "shortterm",
            "description",
            "topic_group",
        ]

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für den Link"),
            "description": _("Beschreibung"),
        }

        widgets = {
            "topic_group": HiddenInput,
        }


class AttachmentCreateForm(forms.ModelForm):
    class Meta:
        model = Attachment

        fields = [
            "title",
            "shortterm",
            "description",
            "topic",
        ]

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für den Link"),
            "description": _("Beschreibung"),
        }

        widgets = {
            "topic": HiddenInput,
        }


class AttachmentUpdateForm(forms.ModelForm):
    class Meta:
        model = Attachment

        fields = [
            "title",
            "shortterm",
            "description",
            "topic",
        ]

        labels = {
            "title": _("Titel"),
            "shortterm": _("Kürzel für den Link"),
            "description": _("Beschreibung"),
        }

        widgets = {
            "topic": HiddenInput,
        }


class EtherpadForm(forms.ModelForm):
    class Meta:
        model = Etherpad

        fields = [
            "title",
            "date",
            "attachment",
        ]

        labels = {
            "title": _("Titel"),
            "date": _("Datum"),
        }

        widgets = {
            "date": DateInput(format=("%Y-%m-%d")),
            "attachment": HiddenInput,
        }


class FileUploadForm(forms.ModelForm):
    class Meta:
        model = FileUpload
        fields = [
            "title",
            "file_field",
            "attachment",
        ]

        widgets = {
            "attachment": HiddenInput,
        }
