import logging

from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList
from wagtail.core.fields import RichTextField

from core.constants import DEFAULT_RICH_TEXT_FEATURES
from core.wagtail_utils import StrictHierarchyPage

logger = logging.getLogger(__name__)


class Topic(StrictHierarchyPage):
    class Meta:
        verbose_name = 'Thema'
        verbose_name_plural = 'Themen'

    order = models.PositiveIntegerField(null=False, blank=False, help_text='Order of the topic')
    teaser = models.TextField()
    description = RichTextField(features=DEFAULT_RICH_TEXT_FEATURES)
    vimeo_id = models.CharField(max_length=200, blank=True, null=True, default=None)
    instructions = models.CharField(max_length=255, blank=True, null=True, default=None)

    content_panels = [
        FieldPanel('title', classname="full title"),
        FieldPanel('order'),
        FieldPanel('teaser'),
        FieldPanel('vimeo_id'),
        FieldPanel('instructions'),
        FieldPanel('description'),
    ]

    settings_panels = [
        FieldPanel('slug')
    ]

    edit_handler = TabbedInterface([
        ObjectList(content_panels, heading='Content'),
        ObjectList(settings_panels, heading='Settings'),
    ])

    template = 'generic_page.html'

    parent_page_types = ['books.Book']
    subpage_types = ['books.Module']
