<?php

function sneakers_sports_shoes_enqueue_fonts() {
    $sneakers_sports_shoes_default_font_content = 'roboto';
    $sneakers_sports_shoes_default_font_heading = 'outfit';

    $sneakers_sports_shoes_font_content = esc_attr(get_theme_mod('sneakers_sports_shoes_content_typography_font', $sneakers_sports_shoes_default_font_content));
    $sneakers_sports_shoes_font_heading = esc_attr(get_theme_mod('sneakers_sports_shoes_heading_typography_font', $sneakers_sports_shoes_default_font_heading));

    $sneakers_sports_shoes_css = '';

    // Always enqueue main font
    $sneakers_sports_shoes_css .= '
    :root {
        --font-main: ' . $sneakers_sports_shoes_font_content . ', ' . (in_array($sneakers_sports_shoes_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('sneakers-sports-shoes-style-font-general', get_template_directory_uri() . '/fonts/' . $sneakers_sports_shoes_font_content . '/font.css');

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

    // Add inline style
    wp_add_inline_style('sneakers-sports-shoes-style-font-general', $sneakers_sports_shoes_css);
}
add_action('wp_enqueue_scripts', 'sneakers_sports_shoes_enqueue_fonts', 50);