# Copyright (c) 2022, JINGROW
# For license information, please see license.txt

import jingrow
from jingrow.website.website_generator import WebsiteGenerator

from jcloud.utils import get_country_info


class SaasSignupGenerator(WebsiteGenerator):
	website = jingrow._dict(
		template="templates/saas/signup.html",
		condition_field="publish",
		page_title_field="app_title",
	)

	def get_context(self, context):
		context.parents = [{"name": "Marketplace App"}]
		country_info = get_country_info() or {}
		country_name = country_info.get("country")
		context.country_name = (
			country_name if jingrow.db.exists("Country", country_name) else ""
		)
		context.enable_google_oauth = jingrow.db.get_single_value(
			"Jcloud Settings", "enable_google_oauth"
		)

		return context

	def validate(self):
		if not self.custom_route:
			self.route = f"{self.app.replace('_', '')}/signup"
