from .XmlTag import XmlTag

class WebStyleSheet (XmlTag):

	def __init__(self):
		XmlTag.__init__(self, 'style')
		self.__rules = []
	
	def add_class(self, names):
		names_list = names.split(" ")
		for name in names_list:
			self.__classes.append(name)

	def add_rule(self, selector, rule):
		self.__rules.append((selector, rule))
		
	def get_rules(self):
		return self.__rules
	
	def get_class(self):
		if len(self.__classes) == 0:
			return None
			
		names = ""
		for i in range(len(self.__classes)):
			names += self.__classes[i]
			if i < len(self.__classes) - 1:
				names += ' '
		return names

	def render_html(self):
		if len(self.get_content()) == 0:
			return ""

		return super().render_html()

	def get_content(self):
		html = ""
		for rule in self.__rules:
			selector = rule[0]
			actual_rule = rule[1]

			html += selector + " { "
			for k in actual_rule:
				v = actual_rule[k]
				html += k + ": " + v + "; "

			html += " }"

		return html