from oscar.forms import widgets as oscar_widgets
from oscar.templatetags.currency_filters import currency


class DataPriceWidgetMixin(object):
    def create_option(
        self, name, value, label, selected, index, subindex=None, attrs=None
    ):
        option = super().create_option(
            name, value, label, selected, index, subindex, attrs
        )
        if value:
            price = label.info.price
            option["attrs"]["data-price"] = currency(price.incl_tax, price.currency)
            option["attrs"]["data-amount-incl-tax"] = price.incl_tax
            option["attrs"]["data-amount-excl-tax"] = price.excl_tax
            option["attrs"]["data-currency"] = price.currency

        return option


class DataPriceSelectWidget(DataPriceWidgetMixin, oscar_widgets.AdvancedSelect):
    pass
