# Copyright (c) 2020, JINGROW
# License: MIT. See LICENSE

import json

import jingrow
from jingrow import _
from jingrow.model.page import Page


class OnboardingStep(Page):
	# begin: auto-generated types
	# This code is auto-generated. Do not modify anything in this block.

	from typing import TYPE_CHECKING

	if TYPE_CHECKING:
		from jingrow.types import DF

		action: DF.Literal[
			"Create Entry", "Update Settings", "Show Form Tour", "View Report", "Go to Page", "Watch Video"
		]
		action_label: DF.Data | None
		callback_message: DF.SmallText | None
		callback_title: DF.Data | None
		description: DF.MarkdownEditor | None
		field: DF.Literal[None]
		form_tour: DF.Link | None
		intro_video_url: DF.Data | None
		is_complete: DF.Check
		is_single: DF.Check
		is_skipped: DF.Check
		path: DF.Data | None
		reference_document: DF.Link | None
		reference_report: DF.Link | None
		report_description: DF.Data | None
		report_reference_pagetype: DF.Data | None
		report_type: DF.Data | None
		show_form_tour: DF.Check
		show_full_form: DF.Check
		title: DF.Data
		validate_action: DF.Check
		value_to_validate: DF.Data | None
		video_url: DF.Data | None

	# end: auto-generated types
	def before_export(self, pg):
		pg.is_complete = 0
		pg.is_skipped = 0


@jingrow.whitelist()
def get_onboarding_steps(ob_steps):
	steps = []
	for s in json.loads(ob_steps):
		pg = jingrow.get_pg("Onboarding Step", s.get("step"))
		step = pg.as_dict().copy()
		step.label = _(pg.title)
		if step.action == "Create Entry":
			step.is_submittable = jingrow.db.get_value(
				"PageType", step.reference_document, "is_submittable", cache=True
			)
		steps.append(step)

	return steps
