<?php

function agriculture_farm_lite_enqueue_fonts() {
    $agriculture_farm_lite_default_font_content = 'inter';
    $agriculture_farm_lite_default_font_heading = 'inter';

    $agriculture_farm_lite_font_content = esc_attr(get_theme_mod('agriculture_farm_lite_content_typography_font', $agriculture_farm_lite_default_font_content));
    $agriculture_farm_lite_font_heading = esc_attr(get_theme_mod('agriculture_farm_lite_heading_typography_font', $agriculture_farm_lite_default_font_heading));

    $agriculture_farm_lite_css = '';

    // Always enqueue main font
    $agriculture_farm_lite_css .= '
    :root {
        --font-main: ' . $agriculture_farm_lite_font_content . ', ' . (in_array($agriculture_farm_lite_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('agriculture-farm-lite-style-font-general', get_template_directory_uri() . '/fonts/' . $agriculture_farm_lite_font_content . '/font.css');

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

    // Add inline style
    wp_add_inline_style('agriculture-farm-lite-style-font-general', $agriculture_farm_lite_css);
}
add_action('wp_enqueue_scripts', 'agriculture_farm_lite_enqueue_fonts', 50);