use crate::ui::prelude::*;
use crate::i18n;

pub( crate ) fn view_language( state: &State ) -> Element<Msg>
{
	let col = column::<Msg>()
		.padding( 24.0 )
		.spacing( 4.0 )
		.push( header( &tr!( "home.language" ) ) )
		.push( list_item( tr!( "language.locale" ) ).trailing( &state.sys_locale ) )
		.push( separator() )
		.push( t_sec!( tr!( "language.language" ) ).size( 13.0 ) );

	// Endonyms render in their own language regardless of the active
	// locale, so the list stays readable while switching.
	let mut list = column::<Msg>().padding( 0.0 ).spacing( 0.0 );
	for lang in i18n::SUPPORTED
	{
		let mut it = list_item( lang.endonym );
		if state.language == lang.code
		{
			it = it.trailing( "✓" );
		} else {
			it = it.on_press( Msg::SetLanguage( lang.code ) );
		}
		list = list.push( it );
	}

	col.push( scroll( list ) ).into()
}
