from django import forms 
from help.models import instruction,static_page,notification
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit,Layout, ButtonHolder,HTML
from datetime import datetime
from django.utils.safestring import mark_safe


class form_instruction(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = "Post" 
         self.helper.add_input(Submit("submit", "Save"))
         self.as_p = True  
      class Meta:
        model = instruction
        fields = ["heading",
                  "content_HTML",
                  "uid"]
        
class form_instruction_search(forms.Form):   
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      #self.helper.form_action = reverse_lazy("index")
      self.helper.form_method = "GET" 
      self.helper.add_input(Submit("submit", "Search"))
   #  self.helper.add_layout(ButtonHolder(    HTML("<span class="hidden">✓ Saved data</span>"),
   #  Submit("save", "Save")))
      
   heading = forms.CharField(max_length=200,required=False,label=mark_safe("<strong> Heading </strong>"),help_text="Search by heading ")



class form_static_page(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = "Post" 
         self.helper.add_input(Submit("submit", "Save"))
         self.as_p = True  
      class Meta:
        model = static_page
        fields = ["heading",
                  "content_HTML",
                  "uid"]
        
class form_static_page_search(forms.Form):   
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      #self.helper.form_action = reverse_lazy("index")
      self.helper.form_method = "GET" 
      self.helper.add_input(Submit("submit", "Search"))
   #  self.helper.add_layout(ButtonHolder(    HTML("<span class="hidden">✓ Saved data</span>"),
   #  Submit("save", "Save")))
      
   heading = forms.CharField(max_length=200,required=False,label=mark_safe("<strong> Heading </strong>"),help_text="Search by heading ") 


class form_notification(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = "Post" 
         self.helper.add_input(Submit("submit", "Save"))
         self.as_p = True  
      class Meta:
        model = notification
        fields = ["header",
                  "body",
                  "type",
                  "exp_date"]
      #exp_date = forms.DateField(required=False, initial=datetime.now(), help_text="Search by expiry date",label="Expiry Date", widget= forms.DateInput(attrs={"type": "date", "min":datetime.now().date()})) 
        
class form_notification_search(forms.Form):   
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      #self.helper.form_action = reverse_lazy("index")
      self.helper.form_method = "GET" 
      self.helper.add_input(Submit("submit", "Search"))
   #  self.helper.add_layout(ButtonHolder(    HTML("<span class="hidden">✓ Saved data</span>"),
   #  Submit("save", "Save")))
      self.as_p = True  

   header = forms.CharField(required=False,max_length=200,help_text="Search by header ",label=mark_safe("<strong> Header </strong>"))
   type = forms.ChoiceField(required=False,label=mark_safe("<strong> Type </strong>"),help_text="Search by type ",choices=[(0,"Not Selected")] +list(notification.objects.all().values_list("type","type"))) 

      
   #header = forms.CharField(max_length=100,required=False,label="Header") 
      