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"),
                ("Yes", "Ano"),
                ("No", "Ne"),
                ("Company info", "Organizace"),
                ("Name cannot be empty", "Jméno nesmí být prázdné"),
                ("Invalid old password", "Neplatné staré heslo"),
                ("Please sign-in to your account", "Přihlaste se prosím k uživatelskému účtu"),
                ("Closed", "Zavřeno"),
                ("Monday", "Pondělí"),
                ("Tuesday", "Úterý"),
                ("Wednesday", "Středa"),
                ("Thursday", "Čtvrtek"),
                ("Friday", "Pátek"),
                ("Saturday", "Sobota"),
                ("Sunday", "Neděle"),
                ("Opening hours", "Otvírací hodiny"),
                ("Username", "Uživatel"),
                ("Password", "Heslo"),
                ("Sign in", "Přihlásit"),
                ("Create user", "Vytvořit uživatele"),
                ("Delete user", "Smazat uživatele"),
                ("Users", "Uživatelé"),
                ("Full name", "Celé jméno"),
                ("Actions", "Akce"),
                ("Edit", "Upravit"),
                ("Change password", "Změnit heslo"),
                ("Delete", "Smazat"),
                ("Properties", "Předměty"),
                ("Name", "Jméno"),
                ("Description", "Popis"),
                ("Price", "Cena"),
                ("Edit hours", "Upravit hodiny"),
                ("Hours", "Hodiny"),
                ("Who is booking", "Kdo rezervuje"),
                ("Reservation", "Rezervace"),
                ("Booking", "Rezervace"),
                ("Enter full name", "Zdejte celé jméno"),
                ("Enter e-mail address", "Zadejte e-mailovou adresu"),
                ("Phone number", "Telefonní číslo"),
                ("Enter phone number", "Zadejte telefonní číslo"),
                ("Book", "Rezervovat"),
                ("Total price of booking", "Celková cena rezervace"),
                ("Date", "Datum"),
                ("Note", "Poznámka"),
                ("Enter note", "Zadejte poznámku"),
                ("New bookings", "Nové rezervace"),
                ("Next approved bookings", "Potvrzené rezervace"),
                ("Approve", "Potvrdit"),
                ("Cancel booking", "Zrušit rezervaci"),
                ("Approve booking", "Potvrdit rezervaci"),
                ("Reservation saved", "Rezervace byla uložena"),
                ("Cancel", "Zrušit"),
                ("Approve booking on ", "Potvrdit rezervaci na "),
                (" for ", " pro "),
                ("Cancel booking on ", "Zrušit rezervaci na "),
                ("Customer: ", "Zákazník: "),
                ("Price: ", "Cena: "),
                ("Note: ", "Poznámka: "),
                ("Overview", "Přehled"),
                ("Can't create reservation", "Rezervaci nelze vytvořit"),
                ("Enter your full name", "Zadejte své jméno"),
                ("Enter valid email address", "Zadejte platný e-mail"),
                ("Select at last one time slot", "Zvolte čas rezervace"),
                ("Enter your phone number", "Zadejte telefonní číslo"),
                ("Your reservation has been successfully saved.", "Vaše rezervace byla úspěšně uložena."),
                ("We look forward to seeing you on", "Těšíme se na vaši návštěvu"),
                ("Create booking", "Vytvořit rezervaci"),
            ])),
            ("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
}