//! Incoming-call screen — full-screen takeover while a call rings inbound.

use ltk::{ column, container, spacer, text, row, Element };

use crate::app::Message;
use crate::palette;
use crate::types::{ Call, ContactRef };
use crate::views::components as ui;

pub fn view( call: &Call, contact: Option<&ContactRef> ) -> Element<Message>
{
	let palette = ltk::theme_palette();

	let title = match contact
	{
		Some( c ) => c.display_name.clone(),
		None      => call.number.as_str().to_string(),
	};

	let subtitle = if contact.is_some()
	{
		call.number.as_str().to_string()
	} else {
		String::from( "Unknown caller" )
	};

	let header = column::<Message>()
		.align_center_x( true )
		.spacing( palette::dp( 16.0 ) )
		.push( text( "Incoming call" ).size( palette::dp( 14.0 ) ).color( palette.text_secondary ).align_center() )
		.push( ui::avatar( contact, 112.0 ) )
		.push( text( title ).size( palette::dp( 28.0 ) ).weight( 600 ).color( palette.text_primary ).align_center() )
		.push( text( subtitle ).size( palette::dp( 14.0 ) ).color( palette.text_secondary ).align_center() );

	let actions = row::<Message>()
		.push( spacer() )
		.push( ui::circle_action( "communication/phone-reject", palette::danger(), Message::Reject ) )
		.push( spacer() )
		.push( ui::circle_action( "communication/phone", palette::accept(), Message::Accept ) )
		.push( spacer() );

	container::<Message>(
		column::<Message>()
			.padding( palette::dp( 24.0 ) )
			.spacing( palette::dp( 28.0 ) )
			.push( spacer() )
			.push( header )
			.push( spacer() )
			.push( actions )
			.push( spacer().height( palette::dp( 24.0 ) ) )
	)
		.background( palette.surface )
		.into()
}
