from django import forms
from .models import GlobalSettings, AdvancedSettings
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field

class GlobalSettingsForm(forms.ModelForm):
    class Meta:
        model = GlobalSettings
        fields = ['site_name', 'contact_email', 'maintenance_mode']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_tag = False
        self.helper.layout = Layout(
            'site_name',
            'contact_email',
            Field('maintenance_mode', template='crispy/checkbox_before_label.html')
        )

class AdvancedSettingsForm(forms.ModelForm):
    class Meta:
        model = AdvancedSettings
        fields = ['enable_analytics', 'analytics_id']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Field('enable_analytics', template='crispy/checkbox_before_label.html'),
            'analytics_id',
        )
