from django.utils.translation import gettext_lazy as _

from wagtail.admin.viewsets.chooser import ChooserViewSet

from ocyan.core.fender import config
from ocyan.main.loading import get_ocyan_classes

# pylint: disable=W0632
(
    ProductChooseView,
    ProductChooseResultsView,
    CategoryChooseView,
    CategoryChooseResultsView,
) = get_ocyan_classes(
    "wagtail_oscar_integration.views",
    [
        "ProductChooseView",
        "ProductChooseResultsView",
        "CategoryChooseView",
        "CategoryChooseResultsView",
    ],
)
# pylint: disable=W0632
BaseProductChooser, BaseChooserWithImage = get_ocyan_classes(
    "wagtail_oscar_integration.chooser.widgets",
    ["BaseProductChooser", "BaseChooserWithImage"],
)

PAGE_SIZE = config.get("oscar", "dashboard_items_per_page", 21)


class ProductViewSet(ChooserViewSet):
    per_page = 13
    model = "catalogue.Product"
    icon = "shopping-cart"
    choose_view_class = ProductChooseView
    choose_results_view_class = ProductChooseResultsView
    choose_one_text = _("Choose a product")
    choose_another_text = _("Choose another product")
    base_widget_class = BaseProductChooser


class CategoryViewSet(ChooserViewSet):
    per_page = 13
    model = "catalogue.Category"
    icon = "regex"
    choose_view_class = CategoryChooseView
    choose_results_view_class = CategoryChooseResultsView
    choose_one_text = _("Choose a category")
    choose_another_text = _("Choose another category")
    base_widget_class = BaseChooserWithImage


product_chooser_viewset = ProductViewSet("product_chooser")
category_chooser_viewset = CategoryViewSet("category_chooser")
