<?php

function vacation_rental_booking_enqueue_fonts() {
    $vacation_rental_booking_default_font_content = 'montserrat';
    $vacation_rental_booking_default_font_heading = 'mansalva';

    $vacation_rental_booking_font_content = esc_attr(get_theme_mod('vacation_rental_booking_content_typography_font', $vacation_rental_booking_default_font_content));
    $vacation_rental_booking_font_heading = esc_attr(get_theme_mod('vacation_rental_booking_heading_typography_font', $vacation_rental_booking_default_font_heading));

    $vacation_rental_booking_css = '';

    // Always enqueue main font
    $vacation_rental_booking_css .= '
    :root {
        --font-main: ' . $vacation_rental_booking_font_content . ', ' . (in_array($vacation_rental_booking_font_content, ['bitter', 'montserrat']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('vacation-rental-booking-style-font-general', get_template_directory_uri() . '/fonts/' . $vacation_rental_booking_font_content . '/font.css');

    // Always enqueue header font
    $vacation_rental_booking_css .= '
    :root {
        --font-head: ' . $vacation_rental_booking_font_heading . ', ' . (in_array($vacation_rental_booking_font_heading, ['bitter', 'montserrat']) ? 'serif' : 'sans-serif') . '!important;
    }';
    wp_enqueue_style('vacation-rental-booking-style-font-h', get_template_directory_uri() . '/fonts/' . $vacation_rental_booking_font_heading . '/font.css');

    // Add inline style
    wp_add_inline_style('vacation-rental-booking-style-font-general', $vacation_rental_booking_css);
}
add_action('wp_enqueue_scripts', 'vacation_rental_booking_enqueue_fonts', 50);