<?php

function cleaning_maintenance_enqueue_fonts() {
    $cleaning_maintenance_default_font_content = 'Roboto';
    $cleaning_maintenance_default_font_heading = 'PlusJakartaSans';

    $cleaning_maintenance_font_content = esc_attr(get_theme_mod('cleaning_maintenance_content_typography_font', $cleaning_maintenance_default_font_content));
    $cleaning_maintenance_font_heading = esc_attr(get_theme_mod('cleaning_maintenance_heading_typography_font', $cleaning_maintenance_default_font_heading));

    $cleaning_maintenance_css = '';

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

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

    // Add inline style
    wp_add_inline_style('cleaning-maintenance-style-font-general', $cleaning_maintenance_css);
}
add_action('wp_enqueue_scripts', 'cleaning_maintenance_enqueue_fonts', 50);