<?php

function elegant_jewellery_enqueue_fonts() {
    $elegant_jewellery_default_font_content = 'libre-baskerville';
    $elegant_jewellery_default_font_heading = 'libre-baskerville';

    $elegant_jewellery_font_content = esc_attr(get_theme_mod('elegant_jewellery_content_typography_font', $elegant_jewellery_default_font_content));
    $elegant_jewellery_font_heading = esc_attr(get_theme_mod('elegant_jewellery_heading_typography_font', $elegant_jewellery_default_font_heading));

    $elegant_jewellery_css = '';

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

    // Always enqueue header font
    $elegant_jewellery_css .= '
    :root {
        --font-head: ' . $elegant_jewellery_font_heading . ', ' . (in_array($elegant_jewellery_font_heading, ['bitter', 'charis-sil']) ? 'serif' : 'serif ') . ' !important;
    }';
    wp_enqueue_style('elegant-jewellery-style-font-h', get_template_directory_uri() . '/fonts/' . $elegant_jewellery_font_heading . '/font.css');

    // Add inline style
    wp_add_inline_style('elegant-jewellery-style-font-general', $elegant_jewellery_css);
}
add_action('wp_enqueue_scripts', 'elegant_jewellery_enqueue_fonts', 50);