// Screen 13 — Smartcast / Link to Dock tutorial.
//
// Same shape as the gestures tutorial: intro card plus three numbered
// steps, parameterised on `step` (0..=3). Step 0 also gets the bullet
// list summarising what Link to Dock can do.

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, widgets };
use crate::ui::theme as t;

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

	let illustration_bytes = match step
	{
		0 => assets::TUTORIAL_SMARTCAST_INTRO,
		1 => assets::TUTORIAL_SMARTCAST_1_A,
		2 => assets::TUTORIAL_SMARTCAST_2,
		_ => assets::TUTORIAL_SMARTCAST_3,
	};

	let ( title_key, subtitle_key, cta_key ) = match step
	{
		0 => (
			"tutorial_smartcast.intro_title",
			"tutorial_smartcast.intro_subtitle",
			"tutorial_smartcast.intro_cta",
		),
		1 => (
			"tutorial_smartcast.step_1_title",
			"tutorial_smartcast.step_1_subtitle",
			"common.next",
		),
		2 => (
			"tutorial_smartcast.step_2_title",
			"tutorial_smartcast.step_2_subtitle",
			"common.next",
		),
		_ => (
			"tutorial_smartcast.step_3_title",
			"tutorial_smartcast.step_3_subtitle",
			"common.done",
		),
	};

	let illustration: Element<Msg> = assets::illustration_widget::<Msg>(
		illustration_bytes,
		chrome::hero_illustration_size(
			state.viewport,
			520,
			if step == 0 { 150 } else { 0 },
		),
	)
	.unwrap_or_else( || spacer().into() );

	let mut content = column::<Msg>()
		.spacing( t::SECTION_SPACING )
		.push( illustration );

	if step == 0
	{
		content = content.push( chrome::title_block(
			&tr!( title_key ),
			Some( &tr!( subtitle_key ) ),
		) );
		content = content.push( widgets::info_card(
			None,
			&[
				tr!( "tutorial_smartcast.intro_bullet_1" ).to_string(),
				tr!( "tutorial_smartcast.intro_bullet_2" ).to_string(),
				tr!( "tutorial_smartcast.intro_bullet_3" ).to_string(),
			],
		) );
	} else {
		content = content.push(
			text( format!( "{}", step ) )
				.size( t::SMALL_SIZE )
				.color( palette.text_primary )
				.align_center(),
		);
		content = content.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::TutorialSmartcast( 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 )
}
