use iced::{
    ContentFit, Element, Task as Command,
    widget::{
        image::{self, Handle},
        stack, text,
    },
};
use iced_layershell::{
    Settings, application,
    reexport::{Anchor, Layer},
    settings::{LayerShellSettings, StartMode},
    to_layer_message,
};

pub fn main() -> Result<(), iced_layershell::Error> {
    let bound_output_name = std::env::args().nth(1);
    let start_mode = match bound_output_name {
        Some(output) => StartMode::TargetScreen(output),
        None => StartMode::Active,
    };

    application(
        || HoneycombHome {},
        HoneycombHome::namespace,
        HoneycombHome::update,
        HoneycombHome::view,
    )
    .settings(Settings {
        layer_settings: LayerShellSettings {
            size: Some((0, 0)),
            exclusive_zone: 0,
            anchor: Anchor::all(),
            start_mode,
            layer: Layer::Background,
            ..Default::default()
        },
        ..Default::default()
    })
    .run()?;

    Ok(())
}

struct HoneycombHome {}

#[to_layer_message]
#[derive(Debug, Clone)]
enum Message {}

impl HoneycombHome {
    fn namespace() -> String {
        String::from("honeycomb home")
    }

    fn update(&mut self, message: Message) -> Command<Message> {
        match message {
            _ => Command::none(),
        }
    }

    fn view(&self) -> Element<'_, Message> {
        let background = image::Image::new(Handle::from_bytes(include_bytes!(
            "res/default_background.png"
        ) as &[u8]))
        .content_fit(ContentFit::Cover);

        stack!(background).push(text("hi :)")).into()
    }
}
