#[cfg(test)]
mod tests;

mod config;
mod elements;
mod error;
mod image_downloader;
mod math_renderer;
mod parser;
#[cfg(feature = "video-thumbnails")]
mod video_thumbnail_extractor;
mod widget;
mod widget_factory;

pub use article_scraper::{DownloadProgress, ImageDownloadError};
pub use config::{
    FontStyle, Justification, WidgetConfig, DEFAULT_FONT_SIZE, DEFAULT_LINE_HEIGHT,
    DEFAULT_PARAGRAPH_SPACING, DEFAULT_SELECTABLE_TEXT,
};
pub use elements::{
    Audio, Code, Element, Figure, Image, InlineWidget, InlineWidgetType, Label, ListBullet,
    ListItem, ListType, Math, MathLang, Paragraph, Table, TableCell, TableRow, TableRowType,
    TagType, TextTag, Video,
};
pub use error::Error;
#[cfg(feature = "image-downloader")]
pub use image_downloader::DefaultImageDownloader;
pub use image_downloader::ImageDownloaderExt;
#[cfg(feature = "mathjax")]
pub use math_renderer::MathJaxRenderer;
pub use math_renderer::MathRendererExt;
#[cfg(feature = "ratex")]
pub use math_renderer::RatexRenderer;
pub use parser::{ParseResult, Parser};
#[cfg(feature = "video-thumbnails")]
pub use video_thumbnail_extractor::{ClientRequestorExt, VideoThumbnailExtractor};
pub use widget::HtmlWidget;
pub use widget_factory::{
    AudioWidget, ImageType, ImageWidget, LabelWithWidgets, MathWidget, VideoWidget, WidgetBuilder,
};

use gtk4::gdk;
use std::sync::atomic::{AtomicBool, Ordering};

static INITIALIZED: AtomicBool = AtomicBool::new(false);

fn load_css() {
    if INITIALIZED.load(Ordering::Relaxed) {
        return;
    }

    let css = include_str!("../data/html2gtk.css");

    let provider = gtk4::CssProvider::new();
    provider.load_from_string(css);

    let Some(display) = gdk::Display::default() else {
        return;
    };

    gtk4::style_context_add_provider_for_display(
        &display,
        &provider,
        gtk4::STYLE_PROVIDER_PRIORITY_THEME + 1,
    );

    INITIALIZED.store(true, Ordering::Relaxed);
}
