from django.db import models
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel

from wagtail.admin.panels import FieldPanel, InlinePanel
from wagtail.contrib.settings.models import BaseSiteSetting, register_setting

from oscar.core.loading import get_model

Product = get_model("catalogue", "Product")
product = Product.objects.all()


@register_setting
class BasketPopupSettings(ClusterableModel, BaseSiteSetting):
    panels = [
        InlinePanel("basket_popup_products", heading="Product"),
    ]


class BasketPopupProducts(models.Model):
    product_setting = ParentalKey(
        BasketPopupSettings, related_name="basket_popup_products"
    )
    product = models.ForeignKey("catalogue.Product", on_delete=models.CASCADE)

    panels = [
        FieldPanel("product"),
    ]
