mod application;
mod leaderboard;
mod map_exercise_view;
mod map_widget;
mod preferences_dialog;
mod quiz;
mod quiz_results_view;
mod region_names;
mod registry;
mod sound_player;
mod window;

mod config {
    #![allow(dead_code)]
    include!(concat!(env!("OUT_DIR"), "/config.rs"));
}

use anyhow::Result;
use gettextrs::{LocaleCategory, bind_textdomain_codeset, bindtextdomain, setlocale, textdomain};
use gio::prelude::*;
use std::path::PathBuf;

use application::MundiApplication;

fn run_application() -> Result<()> {
    // SAFETY: Called at program start before any threads are spawned.
    unsafe { setlocale(LocaleCategory::LcAll, "") };

    let localedir = PathBuf::from(config::DATADIR).join("locale");
    bindtextdomain(config::PACKAGE, localedir)?;
    bind_textdomain_codeset(config::PACKAGE, "UTF-8")?;
    textdomain(config::PACKAGE)?;

    gio::resources_register_include!("resources.gresource")?;

    let app = MundiApplication::new();
    app.run();

    Ok(())
}

fn main() {
    if let Err(e) = run_application() {
        eprintln!("Application initialization failed: {e}");
    }
}
