from django.utils.translation import gettext as _

from wagtail import blocks
from wagtail.embeds.blocks import EmbedBlock
from wagtail.images.blocks import ImageChooserBlock

from ocyan.plugin.coyote.custom_blocks import VisualChoiceBlock
from ocyan.plugin.coyote.struct_values import CoyoteEmbedBlockValue

from .partials import CoyoteButtonBlock, CoyoteInlineBlock


class CoyoteImages(blocks.StructBlock):
    image = ImageChooserBlock(label=_("Image"))
    body = blocks.RichTextBlock(
        label=_("Body"),
        required=True,
        features=["h1", "h2", "h3", "h4", "bold", "italic", "link"],
    )
    image = ImageChooserBlock(label=_("Image"))
    ornaments = CoyoteInlineBlock(
        [
            ("overlay", blocks.BooleanBlock(required=False, label=_("Dark overlay"))),
            (
                "center_text",
                blocks.BooleanBlock(required=False, label=_("Center the body")),
            ),
            ("wave", blocks.BooleanBlock(required=False, label=_("Wave underline"))),
        ],
        label=_("Ornaments"),
    )
    buttons = blocks.ListBlock(
        CoyoteButtonBlock(), label=_("Buttons"), required=False, collapsed=True
    )

    class Meta:
        label = _("Pictures")
        icon = "image"
        template = "coyote/blocks/header/images.html"


class CoyoteVideo(blocks.StructBlock):
    layout = VisualChoiceBlock(
        choices=[
            ("layout1", "coyote/layouts/video_layout_1.png"),
            ("layout2", "coyote/layouts/video_layout_2.png"),
        ],
        default="layout1",
        label=_("Layout"),
    )
    video = EmbedBlock(label=_("Video"), required=False)
    overlay = blocks.BooleanBlock(required=False, label=_("Dark overlay"))
    body = blocks.RichTextBlock(
        label=_("Body"),
        required=True,
        features=["h1", "h2", "h3", "h4", "bold", "italic", "link"],
    )
    buttons = blocks.ListBlock(
        CoyoteButtonBlock(), label=_("Buttons"), required=False, collapsed=True
    )

    class Meta:
        label = _("Video")
        icon = "media"
        template = "coyote/blocks/header/video.html"
        value_class = CoyoteEmbedBlockValue


class CoyoteContent(blocks.StructBlock):
    image = ImageChooserBlock(label=_("Image"))
    position = blocks.ChoiceBlock(
        label=_("Position of the image"),
        choices=[
            ("left", _("Left")),
            ("right", _("Right")),
        ],
        required=False,
    )
    body = blocks.RichTextBlock(
        label=_("Body"),
        required=True,
        features=["h1", "h2", "h3", "h4", "bold", "italic", "link"],
    )
    buttons = blocks.ListBlock(
        CoyoteButtonBlock(), label=_("Buttons"), required=False, collapsed=True
    )

    class Meta:
        label = _("Text")
        icon = "italic"
        template = "coyote/blocks/header/content.html"


class CoyoteCHeaderImages(blocks.StructBlock):
    image = ImageChooserBlock(label=_("Image"))
    overlay = blocks.BooleanBlock(required=False, label=_("Dark overlay"))
    body = blocks.RichTextBlock(
        label=_("Body"),
        required=True,
        features=["h1", "h2", "h3", "h4", "bold", "italic", "link"],
    )
    centered = blocks.BooleanBlock(required=False, label=_("Centered"))
    buttons = blocks.ListBlock(
        CoyoteButtonBlock(), label=_("Buttons"), required=False, collapsed=True
    )
    title = blocks.CharBlock(required=True, label=_("Title"))

    class Meta:
        icon = "image"
        template = "coyote/blocks/header/c_images.html"
