from django import forms
from medic.models import medications,inventory_entry,medic_inhouse,Master_GST
from crispy_forms.helper import FormHelper
from django.utils.safestring import mark_safe
from crispy_forms.layout import Submit,Layout, ButtonHolder,HTML

class form_medications(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 = medications
        fields = ['fk_med',
                  "drug_name",
                "accept",
                "dose",
                "units",
                "frequency",
                "route",
                "duration",
                "days_unit",
                "additional_notes",
                "Ttl_qunaty",
                "ttl_units"]
        
class form_medications_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = "GET" 
      self.helper.add_input(Submit("submit", "Search"))
      self.as_p = True        

# need to add fk_med field
   drug_name = forms.CharField(required=False,max_length=75, help_text="Search by drug name ",label=mark_safe("<strong> Drug Name </strong>")) 
   units = forms.CharField(required=False,max_length=50,help_text="Search by dosage Units ",label=mark_safe("<strong> Units </strong>"))


# class form_disease_details(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 = disease_details

#         fields = ["fk_disease",
#                 "disease_notes",
#                 "status"
#                ]

# class form_disease_details_search(forms.Form):
#    def __init__(self, *args, **kwargs): 
#       super().__init__(*args, **kwargs)
#       self.helper = FormHelper(self)
#       self.helper.form_method = "GET" 
#       #self.helper.add_layout(Layout.)
#       self.helper.add_input(Submit("submit", "Search"))
#       self.helper.add_input(Button("cancel", "Cancel", css_class="btn-danger", onclick="window.history.back()"))
#       self.as_p = True        


#    fk_disease = forms.ChoiceField(required=False,label="Disease", choices=list(disease.objects.all().values_list("id","disease_name"))) 
#    disease_notes = forms.CharField(required=False,max_length=50,help_text="Search by disease Notes",label="Disease Notes")




class form_inventory_entry(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 = inventory_entry
        fields = ["fk_med",
                 # "units",
                  "dosage_unit", "entry_type", "entry_details"]
   
        
class form_inventory_entry_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  
 
   fk_med = forms.ChoiceField(required=False,label=mark_safe("<strong> Medicine </strong>"),help_text="Search by medicine ", choices=[(0,"Not Selected")] +list(medic_inhouse.objects.all().values_list("id","drug_name"))) 
   dosage_unit = forms.FloatField(required=False,widget=forms.NumberInput, help_text="Search by dosage unit ",label=mark_safe("<strong> Dosage Unit </strong>")) 
   entry_type = forms.ChoiceField(required=False, help_text="Search by entry type ",label=mark_safe("<strong> Entry Type </strong>"), choices= inventory_entry.list_type) 
   entry_details = forms.CharField(max_length=150,required=False, help_text="Enter details of the entry like lot# batch #",label=mark_safe("<strong> Entry Details </strong>")) 
   


class form_medic_inhouse(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 = medic_inhouse
        fields = ["drug_name",
                  "drug_tamil",
                  "drug_details",

                  "fk_system","Preparations_type",
                  "group",
                  "packaging",
                  "unit_amount",
                  "fk_GST",]
        
class form_medic_inhouse_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 

   drug_name = forms.CharField(required=False,max_length=75, help_text="Search by drug name ",label=mark_safe("<strong> Drug Name </strong>")) 
   drug_details = forms.CharField(required=False,max_length=250,help_text="Search by drug details ",label=mark_safe("<strong> Drug Details </strong>"))
   fk_GST = forms.ChoiceField(required=False, help_text="Search by GST ",label=mark_safe("<strong> GST </strong>"), choices= [(0,"Not Selected")] +list(Master_GST.objects.all().values_list("id","gst_shorttext"))) 


# class form_med_unit(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 = med_unit
#         fields = ["unit_type"]

        
# class form_med_unit_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")))
      
#    unit_type = forms.CharField(required=False,max_length=50,help_text="Search by unit type ",label=mark_safe("<strong> Unit Type </strong>"))
