from django import forms
from django.forms import NumberInput


class ProductOneTimeOrderForm(forms.Form):
    """
    For products that only contain onetimeresoures
    """

    product = forms.SlugField(required=True, disabled=True)

    def __init__(self, resources, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for res in resources:
            print(res)
            field_name = f"{res.slug}"
            self.fields[field_name] = forms.FloatField(
                required=True,
                label=res.name,
                min_value=res.minimum_units,
                max_value=res.maximum_units,
                widget=NumberInput(attrs={"step": res.step_size}))

            # if res.minimum_units < res.maximum_units:
            #     self.fields[field_name] = forms.FloatField(
            #         required=True,
            #         label=res.name,
            #         min_value=res.minimum_units,
            #         max_value=res.maximum_units,
            #         widget=NumberInput(attrs={"step": res.step_size}))
            # else:
            #     self.fields[field_name] = forms.FloatField(widget=forms.HiddenInput(attrs={'value': res.minimum_units}))

    def clean(self):
        cleaned_data = super().clean()
        print("Cleaning form myself ...")


class ProductOrderForm(ProductOneTimeOrderForm):
    """
    For recurring products (might also have OneTime items)
    """

    timeframe = forms.SlugField(required=False, disabled=True)
