pub mod utils;

use std::io::Cursor;
use js_sys::Uint8Array;
use log::info;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    fn alert(s: &str);
}

#[wasm_bindgen]
pub fn __nxrd_browser_init() {
    wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
    utils::set_panic_hook();
    info!("nexrad-browser initialized successfully");
}

#[wasm_bindgen]
pub fn load_ar2(buf: &JsValue) {
    
    info!("loading archive 2 file");
    info!("load 01: convert to uint8array");
    let array = Uint8Array::new(buf);
    info!("load 02: convert to rust vec");
    let rvec = array.to_vec();
    info!("load 03: create cursor");
    let mut cursor = Cursor::new(rvec);
    info!("load 04: load");
    let loaded = nexrad2::parse_nx2_chunk(&mut cursor).unwrap();
    info!("load 05: dump");
    info!("Loaded: {:#?}", loaded);
}