<?php

function home_construction_builder_enqueue_fonts() {
    $home_construction_builder_default_font_content = 'Poppins';
    $home_construction_builder_default_font_heading = 'Lato';

    $home_construction_builder_font_content = esc_attr(get_theme_mod('home_construction_builder_content_typography_font', $home_construction_builder_default_font_content));
    $home_construction_builder_font_heading = esc_attr(get_theme_mod('home_construction_builder_heading_typography_font', $home_construction_builder_default_font_heading));

    $home_construction_builder_css = '';

    // Always enqueue main font
    $home_construction_builder_css .= '
    :root {
        --font-main: ' . $home_construction_builder_font_content . ', ' . (in_array($home_construction_builder_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('home-construction-builder-style-font-general', get_template_directory_uri() . '/fonts/' . $home_construction_builder_font_content . '/font.css');

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

    // Add inline style
    wp_add_inline_style('home-construction-builder-style-font-general', $home_construction_builder_css);
}
add_action('wp_enqueue_scripts', 'home_construction_builder_enqueue_fonts', 50);