use serde::{Deserialize, Serialize};
use web_sys::{Element, MouseEvent, window};
use wasm_bindgen::UnwrapThrowExt;

#[derive(Debug, Serialize, Deserialize)]
pub struct FileNode {
    pub id: u64,
    pub name: String,
    #[serde(default)]
    pub children: Vec<FileNode>,
}

// this is not required we can do 
// let t : Element = event.target_unchecked_into();
pub trait TargetElement {
    fn target_element<'a>(&self)-> Option<Element>;

}

impl TargetElement for MouseEvent {
    fn target_element(&self) -> Option<Element> {
        // TODO
        //  improve this
        let doc = window().unwrap_throw().document().unwrap_throw();
        let x = self.page_x();
        let y = self.page_y();
        doc.element_from_point(x as f32, y as f32)
    }
}
