<?php

function ott_vlogger_enqueue_fonts() {
    $ott_vlogger_default_font_content = 'IBMPlexSans';
    $ott_vlogger_default_font_heading = 'IBMPlexSans';

    $ott_vlogger_font_content = esc_attr(get_theme_mod('ott_vlogger_content_typography_font', $ott_vlogger_default_font_content));
    $ott_vlogger_font_heading = esc_attr(get_theme_mod('ott_vlogger_heading_typography_font', $ott_vlogger_default_font_heading));

    $ott_vlogger_css = '';

    // Always enqueue main font
    $ott_vlogger_css .= '
    :root {
        --font-main: ' . $ott_vlogger_font_content . ', ' . (in_array($ott_vlogger_font_content, ['bitter', 'charis-sil']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('ott-vlogger-style-font-general', get_template_directory_uri() . '/fonts/' . $ott_vlogger_font_content . '/font.css');

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

    // Add inline style
    wp_add_inline_style('ott-vlogger-style-font-general', $ott_vlogger_css);
}
add_action('wp_enqueue_scripts', 'ott_vlogger_enqueue_fonts', 50);