<?php

function training_institute_academy_enqueue_fonts() {
    $training_institute_academy_default_font_content = 'montserrat';
    $training_institute_academy_default_font_heading = 'Poppins';

    $training_institute_academy_font_content = esc_attr(get_theme_mod('training_institute_academy_content_typography_font', $training_institute_academy_default_font_content));
    $training_institute_academy_font_heading = esc_attr(get_theme_mod('training_institute_academy_heading_typography_font', $training_institute_academy_default_font_heading));

    $training_institute_academy_css = '';

    // Always enqueue main font
    $training_institute_academy_css .= '
    :root {
        --font-main: ' . $training_institute_academy_font_content . ', ' . (in_array($training_institute_academy_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('training-institute-academy-style-font-general', get_template_directory_uri() . '/fonts/' . $training_institute_academy_font_content . '/font.css');

    // Always enqueue header font
    $training_institute_academy_css .= '
    :root {
        --font-head: ' . $training_institute_academy_font_heading . ', ' . (in_array($training_institute_academy_font_heading, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('training-institute-academy-style-font-h', get_template_directory_uri() . '/fonts/' . $training_institute_academy_font_heading . '/font.css');

    // Add inline style
    wp_add_inline_style('training-institute-academy-style-font-general', $training_institute_academy_css);
}
add_action('wp_enqueue_scripts', 'training_institute_academy_enqueue_fonts', 50);