<?php

function green_nursery_enqueue_fonts() {
    $green_nursery_default_font_content = 'libre-baskerville';
    $green_nursery_default_font_heading = 'libre-baskerville';

    $green_nursery_font_content = esc_attr(get_theme_mod('green_nursery_content_typography_font', $green_nursery_default_font_content));
    $green_nursery_font_heading = esc_attr(get_theme_mod('green_nursery_heading_typography_font', $green_nursery_default_font_heading));

    $green_nursery_css = '';

    // Always enqueue main font
    $green_nursery_css .= '
    :root {
        --font-main: ' . $green_nursery_font_content . ', ' . (in_array($green_nursery_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . ' !important;
    }';
    wp_enqueue_style('green-nursery-style-font-general', get_template_directory_uri() . '/fonts/' . $green_nursery_font_content . '/font.css');

    // Always enqueue header font
    $green_nursery_css .= '
    :root {
        --font-head: ' . $green_nursery_font_heading . ', ' . (in_array($green_nursery_font_heading, ['bitter', 'charis-sil']) ? 'serif' : 'serif ') . ' !important;
    }';
    wp_enqueue_style('green-nursery-style-font-h', get_template_directory_uri() . '/fonts/' . $green_nursery_font_heading . '/font.css');

    // Add inline style
    wp_add_inline_style('green-nursery-style-font-general', $green_nursery_css);
}
add_action('wp_enqueue_scripts', 'green_nursery_enqueue_fonts', 50);