from django import forms
from pricemon.models import PriceWatcher

_input = 'w-full border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500'
_mono  = _input + ' font-mono'
_select = _input


class PriceWatcherForm(forms.ModelForm):
    class Meta:
        model = PriceWatcher
        fields = [
            'name', 'url', 'css_selector', 'check_interval_hours',
            'alert_price_threshold', 'recurring_notification', 'enabled',
        ]
        widgets = {
            'name': forms.TextInput(attrs={'class': _input}),
            'url': forms.URLInput(attrs={'class': _input}),
            'css_selector': forms.TextInput(attrs={'class': _mono, 'placeholder': 'e.g. span.price or .product-price'}),
            'check_interval_hours': forms.Select(attrs={'class': _select}),
            'alert_price_threshold': forms.NumberInput(attrs={'class': _input, 'step': '0.01', 'min': '0', 'placeholder': 'e.g. 999.00'}),
            'recurring_notification': forms.CheckboxInput(attrs={'class': 'h-4 w-4 text-indigo-600 border-gray-300 rounded'}),
            'enabled': forms.CheckboxInput(attrs={'class': 'h-4 w-4 text-indigo-600 border-gray-300 rounded'}),
        }
        help_texts = {
            'css_selector': 'CSS selector pointing to the element containing the price text.',
            'alert_price_threshold': 'Notify when detected price is at or below this amount. Leave blank to disable alerts.',
            'recurring_notification': 'Keep notifying on every check while the price meets the threshold. Uncheck to notify only once (until the alert is dismissed).',
        }
