<?php

function aerial_drone_enqueue_fonts() {
    $aerial_drone_default_font_content = 'WorkSans';
    $aerial_drone_default_font_heading = 'WorkSans';

    $aerial_drone_font_content = esc_attr(get_theme_mod('aerial_drone_content_typography_font', $aerial_drone_default_font_content));
    $aerial_drone_font_heading = esc_attr(get_theme_mod('aerial_drone_heading_typography_font', $aerial_drone_default_font_heading));

    $aerial_drone_css = '';

    // Always enqueue main font
    $aerial_drone_css .= '
    :root {
        --font-main: ' . $aerial_drone_font_content . ', ' . (in_array($aerial_drone_font_content, ['bitter', 'Charsil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('aerial-drone-style-font-general', get_template_directory_uri() . '/fonts/' . $aerial_drone_font_content . '/font.css');

    // Always enqueue header font
    $aerial_drone_css .= '
    :root {
        --font-head: ' . $aerial_drone_font_heading . ', ' . (in_array($aerial_drone_font_heading, ['bitter', 'Charsil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('aerial-drone-style-font-h', get_template_directory_uri() . '/fonts/' . $aerial_drone_font_heading . '/font.css');

    // Add inline style
    wp_add_inline_style('aerial-drone-style-font-general', $aerial_drone_css);
}
add_action('wp_enqueue_scripts', 'aerial_drone_enqueue_fonts', 50);