from django.db import models

from wagtail.admin.panels import (
    FieldPanel,
    MultiFieldPanel,
    PublishingPanel,    
)

from wagtail.fields import RichTextField

from wagtail.models import (
    DraftStateMixin,
    PreviewableMixin,
    RevisionMixin,
    TranslatableMixin,
)

from wagtail.contrib.settings.models import (
    BaseGenericSetting,
    register_setting,
)

from wagtail.snippets.models import register_snippet


@register_setting
class NavigationSettings(BaseGenericSetting):
    youtube_url = models.URLField(verbose_name="Youtube URL", blank=True)
    instagram_url = models.URLField(verbose_name="Instagram URL", blank=True)
    facebook_url = models.URLField(verbose_name="Facebook URL", blank=True)
    gitea_url = models.URLField(verbose_name="Gitea URL", blank=True)

    panels = [
        MultiFieldPanel(
            [
                FieldPanel("youtube_url"),
                FieldPanel("instagram_url"),
                FieldPanel("facebook_url"),
                FieldPanel("gitea_url"),
            ],
            "Social settings",
        )
    ]
    
@register_snippet
class FooterText(
    DraftStateMixin,
    RevisionMixin,
    PreviewableMixin,
    TranslatableMixin,
    models.Model,
):

    body = RichTextField()

    panels = [
        FieldPanel("body"),
        PublishingPanel(),
    ]

    def __str__(self):
        return "Footer text"

    def get_preview_template(self, request, mode_name):
        return "base.html"

    def get_preview_context(self, request, mode_name):
        return {"footer_text": self.body}

    class Meta(TranslatableMixin.Meta):
        verbose_name_plural = "Footer Text"