from django.utils.translation import gettext as _
from roadrunner.blocks import BaseStylingBlock

from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock


class PopupBlock(blocks.StructBlock):
    header = blocks.CharBlock(required=False)
    body = blocks.RichTextBlock(label=_("Body"), required=False)
    button_label = blocks.CharBlock(required=False)
    button_link = blocks.URLBlock(required=False)

    class Meta:
        label = "popup"
        icon = "duplicate"
        roadrunner_options = {"group": "extra"}
        group = "extra"


class ImageLinkBlock(blocks.StructBlock):
    image = ImageChooserBlock(required=False)
    link = blocks.CharBlock(required=False)

    class Meta:
        label = "imagelink"
        icon = "link"
        roadrunner_options = {"group": "extra"}
        group = "extra"


class BetterSliderBlock(blocks.StructBlock):
    image = ImageChooserBlock(required=False)
    body = blocks.RichTextBlock(required=False)
    position = blocks.ChoiceBlock(
        choices=[
            ("top-left", "Top left"),
            ("top-right", "Top right"),
            ("bottom-left", "Bottom left"),
            ("bottom-right", "Bottom right"),
            ("middle-left", "Middle left"),
            ("middle", "Middle"),
            ("middle-right", "Middle right"),
        ],
        required=False,
    )
    ribbon_color = blocks.CharBlock(required=False)
    ribbon_position = blocks.ChoiceBlock(
        choices=[("left", "Left"), ("right", "Right")], required=False
    )
    height = blocks.CharBlock(required=False)
    styling = BaseStylingBlock()


class BetterButtonBlock(blocks.StructBlock):
    label = blocks.CharBlock(required=False)
    url = blocks.CharBlock(required=False)
    classes = blocks.CharBlock(required=False)
    new_tab = blocks.BooleanBlock(
        required=False, default=False, label="Open in new tab"
    )

    class Meta:
        icon = "bold"
        label = "button x"
        roadrunner_options = {"group": "extra"}
        group = "extra"


def BetterSliderListBlock(**kwargs):
    kwargs.setdefault("template", "oxyan/blocks/better_slider.html")
    kwargs.setdefault("label", "slider x")
    kwargs.setdefault("icon", "strikethrough")
    kwargs.setdefault("roadrunner_options", {"group": "extra"})
    kwargs.setdefault("group", "extra")
    return blocks.ListBlock(BetterSliderBlock(), **kwargs)
