use web_sys::wasm_bindgen::JsCast;
use wxbox_client::WxboxApp;

fn main() {
    console_error_panic_hook::set_once();
    wasm_tracing::set_as_global_default();

    let web_options = eframe::WebOptions::default();
    wasm_bindgen_futures::spawn_local(async {
        let document = web_sys::window()
            .expect("no window?")
            .document()
            .expect("no document?");

        let canvas = document
            .get_element_by_id("target")
            .expect("failed to find target canvas for rendering")
            .dyn_into::<web_sys::HtmlCanvasElement>()
            .expect("#target is not a canvas");

        eframe::WebRunner::new()
            .start(
                canvas,
                web_options,
                Box::new(|cc| Ok(Box::new(WxboxApp::new(cc.egui_ctx.clone())))),
            )
            .await
            .expect("failed to start eframe")
    })
}
