from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core.fields import StreamField, RichTextField
from wagtail.images.blocks import ImageChooserBlock

from books.blocks import LinkBlock, VideoBlock, DocumentBlock, SectionTitleBlock, InfogramBlock, \
    GeniallyBlock, InstrumentTextBlock, SubtitleBlock, ThinglinkBlock
from core.constants import DEFAULT_RICH_TEXT_FEATURES
from core.wagtail_utils import StrictHierarchyPage


class BasicKnowledge(StrictHierarchyPage):
    parent_page_types = ['books.book']

    intro = RichTextField(features=DEFAULT_RICH_TEXT_FEATURES, default='', blank=True)

    contents = StreamField([
        ('text_block', InstrumentTextBlock()),
        ('image_block', ImageChooserBlock()),
        ('link_block', LinkBlock()),
        ('video_block', VideoBlock()),
        ('document_block', DocumentBlock()),
        ('section_title', SectionTitleBlock()),
        ('infogram_block', InfogramBlock()),
        ('genially_block', GeniallyBlock()),
        ('thinglink_block', ThinglinkBlock()),
        ('subtitle', SubtitleBlock()),
    ], null=True, blank=True)

    LANGUAGE_COMMUNICATION = 'language_communication'
    SOCIETY = 'society'
    INTERDISCIPLINARY = 'interdisciplinary'

    TYPE_CHOICES = (
        (LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'),
        (SOCIETY, 'Gesellschaft'),
        (INTERDISCIPLINARY, 'Überfachliches Instrument'),
    )

    type = models.CharField(
        max_length=100,
        choices=TYPE_CHOICES
    )

    content_panels = [
        FieldPanel('title', classname="full title"),
        FieldPanel('type'),
        FieldPanel('intro'),
        StreamFieldPanel('contents')
    ]

    class Meta:
        verbose_name = 'Instrument'
