from django.utils.translation import gettext as _

from wagtail import blocks

from ocyan.main.loading import get_baseclass
from ocyan.plugin.coyote.blocks.partials import CoyoteStructBlock
from ocyan.plugin.coyote.custom_blocks import IconChoiceBlock, VisualChoiceBlock
from ocyan.plugin.coyote.icons import ICONS

# pylint: disable=E0401,E0611
from ocyan.plugin.wagtail_oscar_integration.blocks import (
    CategoryChooserBlock,
    ProductChooserBlock,
)

BaseHomePageContentStreamBlock = get_baseclass(
    "coyote.stream_blocks",
    "HomePageContentStreamBlock",
    "ocyan.plugin.wagtail_oscar_integration.wagtail_oscar_integration_coyote_extension",
)


class CoyoteProductsBlock(CoyoteStructBlock):
    layout = VisualChoiceBlock(
        choices=[
            ("layout1", "coyote/layouts/products_layout_1.png"),
            ("layout2", "coyote/layouts/products_layout_2.png"),
        ]
    )
    body = blocks.RichTextBlock(required=False, label=_("Short text"))
    read_more_button = blocks.CharBlock(
        required=False, label=_("Read more button"), default=_("More articles")
    )
    read_more_link = blocks.URLBlock(required=False, label=_("Read more url"))
    products = blocks.ListBlock(
        ProductChooserBlock(), required=False, label=_("Products")
    )

    class Meta:
        template = "coyote/blocks/content/productsblock.html"


class CoyoteCategorychooser(blocks.StructBlock):
    icon = IconChoiceBlock(choices=ICONS, required=False)
    category = CategoryChooserBlock()


class CoyoteCategoryBlock(CoyoteStructBlock):
    layout = VisualChoiceBlock(
        choices=[
            ("layout1", "coyote/layouts/category_layout_1.png"),
            ("layout2", "coyote/layouts/category_layout_2.png"),
        ]
    )
    body = blocks.RichTextBlock(required=False, label=_("Short text"))
    read_more_button = blocks.CharBlock(
        required=False, label=_("Read more button"), default=_("More articles")
    )
    read_more_link = blocks.URLBlock(required=False, label=_("Read more url"))
    categories = blocks.ListBlock(
        CoyoteCategorychooser(), required=False, label=_("Categories")
    )

    class Meta:
        template = "coyote/blocks/content/categoryblock.html"


class HomePageContentStreamBlock(BaseHomePageContentStreamBlock):
    Products = CoyoteProductsBlock(icon="tag")
    Category = CoyoteCategoryBlock(icon="folder")
