from wagtail import blocks
from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.images.blocks import ImageChooserBlock

from ocyan.core.fender import config
from ocyan.main.loading import get_ocyan_class
from ocyan.plugin.wagtail.block_plugin import get_block_choices
from ocyan.plugin.wagtail.blocks import WrappedCharBlock

CallToActionBlock = get_ocyan_class("wagtail_content_page.blocks", "CallToActionBlock")

CONTENT_PAGE_STREAMFIELDS = [
    ("heading", WrappedCharBlock(classname="full title", tag="h1")),
    ("paragraph", blocks.RichTextBlock()),
    ("image", ImageChooserBlock()),
    ("table", TableBlock()),
    ("actionbuttons", CallToActionBlock()),
    ("html", blocks.RawHTMLBlock()),
]


def is_enabled(field):
    name, _ = field
    return config.get("wagtail content page", name, True)


def streamfields():
    return [
        field for field in CONTENT_PAGE_STREAMFIELDS if is_enabled(field)
    ] + get_block_choices("contentpage")
