use crate::ui::prelude::*;
use crate::storage;

pub( crate ) fn view_about( state: &State ) -> Element<Msg>
{
	let mem_total = storage::fmt_bytes( state.total_memory );
	let mem_used  = storage::fmt_bytes( state.used_memory );
	let mem_str   = format!( "{} / {}", mem_used, mem_total );
	let cpu_str   = tr!( "about.cores", model = &state.cpu_model, n = state.cpu_cores );
	let uptime    = fmt_uptime( state.uptime_secs );
	let not_conn  = tr!( "about.not_connected" );
	let ip_str    = state.primary_ip.as_deref().unwrap_or( &not_conn );

	scroll(
		column::<Msg>()
			.padding( 24.0 )
			.spacing( 4.0 )
			.push( header( &tr!( "home.about" ) ) )
			.push( list_item( tr!( "about.device_name" ) ).trailing( &state.hostname ) )
			.push( list_item( tr!( "about.user" ) ).trailing( &state.username ) )
			.push( section_sep() )
			.push( list_item( tr!( "about.os" ) ).trailing( &state.os_version ) )
			.push( list_item( tr!( "about.kernel" ) ).trailing( &state.kernel ) )
			.push( section_sep() )
			.push( list_item( tr!( "about.processor" ) ).subtitle( cpu_str ) )
			.push( list_item( tr!( "about.memory" ) ).trailing( &mem_str ) )
			.push( section_sep() )
			.push( list_item( tr!( "about.uptime" ) ).trailing( &uptime ) )
			.push( list_item( tr!( "about.ip" ) ).trailing( ip_str ) )
			.push( spacer() )
	)
	.into()
}
