// Screen 11 — Install finish.

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

use crate::app::Msg;
use crate::assets;
use crate::i18n::tr;
use crate::state::State;
use crate::ui::{ chrome, widgets };
use crate::ui::theme as t;

pub fn view( state: &State ) -> Element<Msg>
{
	let palette = ltk::theme_palette();
	let install_mode = state.mode == crate::state::WizardMode::Install;

	let check: Element<Msg> = assets::illustration_widget::<Msg>(
		assets::INSTALL_FINISH,
		160,
	)
	.unwrap_or_else( || spacer().into() );

	// Install mode ends with "remove the medium and restart"; the
	// Configure flow keeps the figma finish with the tutorials CTA.
	let ( title, subtitle, card_lines, cta_label, cta_msg, hint ) = if install_mode
	{
		(
			tr!( "finish.install_title" ),
			tr!( "finish.install_subtitle" ),
			vec![ tr!( "finish.install_remove_medium" ).to_string() ],
			tr!( "finish.install_cta" ),
			Msg::Reboot,
			None,
		)
	}
	else
	{
		(
			tr!( "finish.title" ),
			tr!( "finish.subtitle" ),
			vec![
				tr!( "finish.bullet_1" ).to_string(),
				tr!( "finish.bullet_2" ).to_string(),
				tr!( "finish.bullet_3" ).to_string(),
			],
			tr!( "finish.cta" ),
			Msg::DiscoverDevice,
			Some( tr!( "finish.hint" ).to_string() ),
		)
	};

	let card = widgets::info_card( None, &card_lines );

	// The inner spacers keep the block vertically centred while it fits.
	let content = column::<Msg>()
		.spacing( t::SECTION_SPACING )
		.push( spacer() )
		.push( check )
		.push( chrome::title_block( &title, Some( &subtitle ) ) )
		.push( card )
		.push( spacer() );

	let mut body = column::<Msg>()
		.padding( t::PAGE_PADDING_H )
		.spacing( t::SECTION_SPACING )
		.push( scroll( content ) )
		.push( chrome::primary_cta( &cta_label, Some( cta_msg ) ) );
	if let Some( hint ) = hint
	{
		body = body.push(
			text( hint )
				.size( t::SMALL_SIZE )
				.color( palette.text_secondary )
				.align_center(),
		);
	}

	chrome::page( body )
}
