// Screen 12 — Gesture tutorial.
//
// Four-page sub-flow: an intro card and three numbered steps. The
// `step` argument is `0..=3`; see `flow::next` for transitions.

use ltk::
{
	Element,
	column, scroll, spacer, text,
};

use crate::app::Msg;
use crate::assets;
use crate::flow::Screen;
use crate::i18n::tr;
use crate::state::State;
use crate::ui::chrome;
use crate::ui::theme as t;

pub fn view( state: &State, step: u8 ) -> Element<Msg>
{
	let palette = ltk::theme_palette();

	let ( illustration_bytes, title_key, subtitle_key, cta_key ) = match step
	{
		0 => (
			assets::TUTORIAL_GESTURES_INTRO,
			"tutorial_gestures.intro_title",
			"tutorial_gestures.intro_subtitle",
			"tutorial_gestures.intro_cta",
		),
		1 => (
			assets::TUTORIAL_GESTURES_1,
			"tutorial_gestures.step_1_title",
			"tutorial_gestures.step_1_subtitle",
			"common.next",
		),
		2 => (
			assets::TUTORIAL_GESTURES_2,
			"tutorial_gestures.step_2_title",
			"tutorial_gestures.step_2_subtitle",
			"common.next",
		),
		_ => (
			assets::TUTORIAL_GESTURES_3,
			"tutorial_gestures.step_3_title",
			"tutorial_gestures.step_3_subtitle",
			"common.done",
		),
	};

	let illustration: Element<Msg> = assets::illustration_widget::<Msg>(
		illustration_bytes,
		chrome::hero_illustration_size( state.viewport, 420, 0 ),
	)
	.unwrap_or_else( || spacer().into() );

	let step_pip: Element<Msg> = if step == 0
	{
		spacer().into()
	} else {
		text( format!( "{}", step ) )
			.size( t::SMALL_SIZE )
			.color( palette.text_primary )
			.align_center()
			.into()
	};

	let content = column::<Msg>()
		.spacing( t::SECTION_SPACING )
		.push( illustration )
		.push( step_pip )
		.push( chrome::title_block(
			&tr!( title_key ),
			Some( &tr!( subtitle_key ) ),
		) );

	let body = column::<Msg>()
		.padding( t::PAGE_PADDING_H )
		.spacing( t::SECTION_SPACING )
		.push( chrome::top_bar( Screen::TutorialGestures( step ), true, state.mode ) )
		.push( scroll( content ) )
		.push( chrome::primary_cta( &tr!( cta_key ), Some( Msg::Next ) ) )
		.push( chrome::skip_link(
			&tr!( "common.skip_tutorial" ),
			Msg::SkipTutorial,
		) );

	chrome::page( body )
}
