<?php

function solar_energy_engine_enqueue_fonts() {
    $solar_energy_engine_default_font_content = 'Poppins';
    $solar_energy_engine_default_font_heading = 'Poppins';

    $solar_energy_engine_font_content = esc_attr(get_theme_mod('solar_energy_engine_content_typography_font', $solar_energy_engine_default_font_content));
    $solar_energy_engine_font_heading = esc_attr(get_theme_mod('solar_energy_engine_heading_typography_font', $solar_energy_engine_default_font_heading));

    $solar_energy_engine_css = '';

    // Always enqueue main font
    $solar_energy_engine_css .= '
    :root {
        --font-main: ' . $solar_energy_engine_font_content . ', ' . (in_array($solar_energy_engine_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('solar-energy-engine-style-font-general', get_template_directory_uri() . '/fonts/' . $solar_energy_engine_font_content . '/font.css');

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

    // Add inline style
    wp_add_inline_style('solar-energy-engine-style-font-general', $solar_energy_engine_css);
}
add_action('wp_enqueue_scripts', 'solar_energy_engine_enqueue_fonts', 50);