<?php

function multi_sports_club_enqueue_fonts() {
    $multi_sports_club_default_font_content = 'IBMPlexSans';
    $multi_sports_club_default_font_heading = 'IBMPlexSans';

    $multi_sports_club_font_content = esc_attr(get_theme_mod('multi_sports_club_content_typography_font', $multi_sports_club_default_font_content));
    $multi_sports_club_font_heading = esc_attr(get_theme_mod('multi_sports_club_heading_typography_font', $multi_sports_club_default_font_heading));

    $multi_sports_club_css = '';

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

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

    // Add inline style
    wp_add_inline_style('multi-sports-club-style-font-general', $multi_sports_club_css);
}
add_action('wp_enqueue_scripts', 'multi_sports_club_enqueue_fonts', 50);