use ltk::{ Element, WallpaperBundle };

use crate::message::Msg;
use crate::state::{ State, UnlockMethod };

/// Main surface: the unlock form over the theme's `lockscreen` background. It
/// is rendered throughout — the idle panel (see [`idle_subsurface`]) sits on a
/// subsurface above it and slides up to reveal it. The form is non-interactive
/// until `revealed` (see [`crate::lockscreen_password`]), so input falling
/// through the idle panel during the slide does nothing.
pub fn view( state: &State ) -> Element<Msg>
{
	let content = match state.method
	{
		UnlockMethod::Password    => crate::lockscreen_password::view( state ),
		UnlockMethod::Pin         => placeholder( "PIN" ),
		UnlockMethod::Gesture     => placeholder( "gesture" ),
		UnlockMethod::Fingerprint => placeholder( "fingerprint" ),
	};

	backdrop( state.lockscreen_wp.as_ref(), content, state )
}

/// Content for the input-transparent idle subsurface: the clock panel over the
/// theme's `wallpaper` background, fully covering the main surface until the
/// runtime slides it up as the unlock drag progresses.
pub fn idle_subsurface( state: &State ) -> Element<Msg>
{
	backdrop( state.wallpaper.as_ref(), crate::idle::view( state ), state )
}

fn backdrop( wp: Option<&WallpaperBundle>, content: Element<Msg>, state: &State ) -> Element<Msg>
{
	match wp
	{
		Some( wp ) => ltk::backdrop( content, wp, state.surface_w, state.surface_h ),
		None       => content,
	}
}

fn placeholder( name: &str ) -> Element<Msg>
{
	ltk::text( format!( "{name} unlock — not yet implemented" ) ).into()
}
