<?php

function modern_art_gallery_enqueue_fonts() {
    $modern_art_gallery_default_font_content = 'mulish';
    $modern_art_gallery_default_font_heading = 'mulish';

    $modern_art_gallery_font_content = esc_attr(get_theme_mod('modern_art_gallery_content_typography_font', $modern_art_gallery_default_font_content));
    $modern_art_gallery_font_heading = esc_attr(get_theme_mod('modern_art_gallery_heading_typography_font', $modern_art_gallery_default_font_heading));

    $modern_art_gallery_css = '';

    // Always enqueue main font
    $modern_art_gallery_css .= '
    :root {
        --font-main: ' . $modern_art_gallery_font_content . ', ' . (in_array($modern_art_gallery_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('modern-art-gallery-style-font-general', get_template_directory_uri() . '/fonts/' . $modern_art_gallery_font_content . '/font.css');

    // Always enqueue header font
    $modern_art_gallery_css .= '
    :root {
        --font-head: ' . $modern_art_gallery_font_heading . ', ' . (in_array($modern_art_gallery_font_heading, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('modern-art-gallery-style-font-h', get_template_directory_uri() . '/fonts/' . $modern_art_gallery_font_heading . '/font.css');

    // Add inline style
    wp_add_inline_style('modern-art-gallery-style-font-general', $modern_art_gallery_css);
}
add_action('wp_enqueue_scripts', 'modern_art_gallery_enqueue_fonts', 50);