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

pub( crate ) fn view_notifications( state: &State ) -> Element<Msg>
{
	let mut col = column::<Msg>()
		.padding( 24.0 )
		.spacing( 8.0 )
		.push( header( &tr!( "home.notifications" ) ) )
		.push(
			toggle( state.dnd_enabled )
				.label( tr!( "notifications.dnd" ) )
				.on_toggle( Msg::ToggleDnd )
		)
		.push( separator() )
		.push(
			toggle( state.lockscreen_show_notifs )
				.label( tr!( "notifications.show_on_lock" ) )
				.on_toggle( Msg::ToggleLockscreenNotifs )
		)
		.push( section_sep() )
		.push( t_sec!( tr!( "notifications.channels" ) ).size( 13.0 ) );

	if state.notif_channels.is_empty()
	{
		col = col.push( t_sec!( tr!( "notifications.no_channels" ) ).size( 12.0 ) );
	}

	// One toggle per channel (on = allowed, off = blocked), grouped by app.
	let mut last_app = String::new();
	for c in &state.notif_channels
	{
		if c.app_id != last_app
		{
			col = col.push( t_sec!( c.app_id.clone() ).size( 12.0 ) );
			last_app = c.app_id.clone();
		}
		col = col.push(
			toggle( !c.blocked )
				.label( c.name.clone() )
				.on_toggle( Msg::ToggleChannelBlocked( c.app_id.clone(), c.channel_id.clone() ) )
		);
	}

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