import jingrow
from jingrow.website.page_renderers.document_page import DocumentPage
from jingrow.website.router import get_page_info_from_web_form


class WebFormPage(DocumentPage):
	def can_render(self):
		web_form = get_page_info_from_web_form(self.path)
		if web_form:
			self.pagetype = "Web Form"
			self.pagename = web_form.name
			self.set_headers()
			return True
		else:
			return False

	def set_headers(self):
		pg = jingrow.get_cached_pg(self.pagetype, self.pagename)
		allowed_embedding_domains = pg.allowed_embedding_domains
		if allowed_embedding_domains:
			allowed_embedding_domains = allowed_embedding_domains.replace("\n", " ")
			self.headers = {"Content-Security-Policy": f"frame-ancestors 'self' {allowed_embedding_domains}"}
