<?php

function trucking_company_enqueue_fonts() {
    $trucking_company_default_font_content = 'roboto';
    $trucking_company_default_font_heading = 'roboto';

    $trucking_company_font_content = esc_attr(get_theme_mod('trucking_company_content_typography_font', $trucking_company_default_font_content));
    $trucking_company_font_heading = esc_attr(get_theme_mod('trucking_company_heading_typography_font', $trucking_company_default_font_heading));

    $trucking_company_css = '';

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

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

    // Add inline style
    wp_add_inline_style('trucking-company-style-font-general', $trucking_company_css);
}
add_action('wp_enqueue_scripts', 'trucking_company_enqueue_fonts', 50);