import uuid

from django.utils.translation import gettext as _

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

from ocyan.plugin.coyote.blocks.partials import CoyoteButtonBlock, CoyoteStructBlock
from ocyan.plugin.coyote.custom_blocks import VisualChoiceBlock


class CoyoteContent(blocks.StructBlock):
    layout = VisualChoiceBlock(
        choices=[
            ("layout1", "carbasa/layouts/content_layout_1.png"),
            ("layout2", "carbasa/layouts/content_layout_2.png"),
        ],
        default="layout1",
        label=_("Layout"),
    )
    image = ImageChooserBlock(label=_("Image"))
    secondairy_image = ImageChooserBlock(label=_("Image"), required=False)
    tertiary_image = ImageChooserBlock(label=_("Image"), 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
    )
    go_to_text = blocks.CharBlock(label=_("Cta text"), required="False")
    go_to_link = blocks.CharBlock(label=_("Cta link"), required="False")

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


class BootstrapTabBlock(blocks.StructBlock):
    header = blocks.CharBlock(label=_("Title"))
    body = blocks.RichTextBlock(label=_("Body"))
    image = ImageChooserBlock(label=_("Image"))
    button = CoyoteButtonBlock(required=False, label=_("Button"))


class CoyoteTabsBlock(CoyoteStructBlock):
    header = blocks.CharBlock(label=_("Title"), required=False)
    body = blocks.RichTextBlock(label=_("Body"), required=False)
    tabs = blocks.ListBlock(
        BootstrapTabBlock(), label=_("Tabbed content"), required=False, collapsed=True
    )

    def get_uuid(self):
        return uuid.uuid4()

    class Meta:
        icon = "table"
        template = "carbasa/blocks/tabsblock.html"


class CoyoteCallToAction(blocks.StructBlock):
    header = blocks.CharBlock(required=False, label=_("Title"))
    body = blocks.RichTextBlock(required=False, label=_("Body"))
    button = CoyoteButtonBlock(required=False, label=_("Button"))

    class Meta:
        template = "carbasa/blocks/calltoaction.html"
        icon = "pick"


class CarbasaQuoteBlock(blocks.StructBlock):
    stars = blocks.CharBlock(required=False, label=_("Stars"))
    image = ImageChooserBlock(required=False, label=_("Image"))
    name = blocks.CharBlock(required=False, label=_("Full name"))
    function = blocks.CharBlock(required=False, label=_("Function"))
    header = blocks.TextBlock(required=False, label=_("Header"))
    quote = blocks.TextBlock(required=False, label="Quote")


class CoyoteQuotesBlock(CoyoteStructBlock):
    image = ImageChooserBlock(required=False, label="Afbeelding")
    quotes = blocks.ListBlock(
        CarbasaQuoteBlock(), required=True, collapsed=True, label=_("Quotes")
    )

    class Meta:
        template = "coyote/blocks/content/quotesblock.html"
        icon = "openquote"


class CoyotePersonListBlock(CoyoteStructBlock):
    b1_tagline = blocks.CharBlock(required=False, label="Tagline¹")
    b1_header = blocks.CharBlock(required=False, label="Header¹")
    b1_cta = blocks.CharBlock(required=False, label="CallToAction¹", default="Shop now")
    b1_link = blocks.URLBlock(required=False, label="Link¹", default="Shop now")
    b1_image = ImageChooserBlock(required=False, label="Image¹")
    b2_tagline = blocks.CharBlock(required=False, label="Tagline²")
    b2_header = blocks.CharBlock(required=False, label="Header²")
    b2_cta = blocks.CharBlock(required=False, label="CallToAction²", default="Shop now")
    b2_link = blocks.URLBlock(required=False, label="Link²", default="Shop now")
    b2_image = ImageChooserBlock(required=False, label="Image²")

    class Meta:
        label = "koeien"
        template = "coyote/blocks/content/banner_block.html"
