use std::collections::HashMap;
use lazy_static::lazy_static;
use leptos::*;
use crate::locales::Locales;

lazy_static! {
    static ref LANGUAGES: HashMap<&'static str, HashMap<&'static str, &'static str>> = {
        let m = HashMap::from([
            ("cs", HashMap::from( [
                ("Dashboard", "Přehled"),
                ("Settings", "Nastavení"),
                ("Search...", "Najít..."),
                ("Close", "Zavřít"),
                ("Save changes", "Uložit změny"),
                ("Company info", "Organizace"),
                ("Name cannot be empty", "Jméno nesmí být prázdné"),
            ])),
            ("sk", HashMap::from( [
                ("Dashboard", "Prehlad"),
                ("Settings", "Nastavenie"),
                ("Search...", "Najsť...")
            ]))
        ]);
        m
    };
}

pub fn get_dictionary() -> Option<&'static HashMap<&'static str, &'static str>> {
    let locs = use_context::<Locales>().unwrap_or(Locales(vec![])).0;
    for loc in locs {
        if let Some(key) = loc {
            if let Some(k) = key.split("-").collect::<Vec<_>>().get(0) {
                if *k == "en" {
                    return None;
                }
                if !LANGUAGES.contains_key(*k) {
                    continue;
                }
                return LANGUAGES.get(*k);
            }
        }
    }

    None
}