<?

// Return now if the font customizer is disabled
if (empty($this_website['website_settings']['fonts_allow_customizer'])){ return; }

// Print out the commented title for this stylesheet
echo '/* -- CUSTOM FONT STYLES -- */'.PHP_EOL;

// Loop through font settings again and generate style search/replace rules
$font_fields = array('fonts_include_base_family', 'fonts_include_other_family');
$font_families = array();
$font_families_targets = array();
foreach ($font_fields AS $field_name){
    // Only continue if the setting exists and isn't empty
    if (!empty($this_website['website_settings'][$field_name])){
        // Break apart the value string into its individual parts
        $setting_value = $this_website['website_settings'][$field_name];
        list($source, $name, $category, $families) = explode('|', $setting_value);
        // Generate a variable containing this font family rule
        $kind = preg_replace('/^fonts_include_([a-z0-9]+)_family$/i', '$1', $field_name);
        $font_families[$kind] = $families;
        // Collect targets for this font from related settings
        $font_families_targets[$kind] = array();
        if (!empty($this_website['website_settings']['fonts_target_'.$kind.'_family'])){
            $font_families_targets[$kind] = $this_website['website_settings']['fonts_target_'.$kind.'_family'];
        }
    }
}

// BASE FONT FAMILY

// Continue only if the base font family was not empty
if (!empty($font_families['base'])){

    // Apply if "website" is in the list of base font targets (should always be)
    if (in_array('website', $font_families_targets['base'])){
        ?>
            html,
            body,
            .website,
            .website .content,
            .website .content p,
            .website .content div,
            .content .block_form button.button,
            .content .block_form input.button,
            .content .block_form a.button,
            .content.menu_section .menu_item td.price,
            .custom_font.base {
                font-family: <?= $font_families['base'] ?>;
            }
        <?
    }

}

// OTHER FONT FAMILY

// Continue only if the base font family was not empty
if (!empty($font_families['other'])){

    // Apply if "navbar" is in the list of other font targets
    if (in_array('navbar', $font_families_targets['other'])){
        ?>

            .nav .list_pages .item_page {
                font-family: <?= $font_families['other'] ?>;
            }

        <?
    }

    // Apply if "headers" is in the list of other font targets
    if (in_array('headers', $font_families_targets['other'])){
        ?>

            .website .content h1,
            .website .content h2,
            .website .content h3,
            .website .content h4,
            .website .content h5,
            .website .content h6,
            .website .menu_section .menu_item h4.item_name,
            .website .footer .footer_column .name,
            .website .footer .footer_column .connect,
            .website .footer .footer_column .sitemap,
            .custom_font.other.headers {
                font-family: <?= $font_families['other'] ?>;
            }

        <?
    }

    // Apply if "buttons" is in the list of other font targets
    if (in_array('buttons', $font_families_targets['other'])){
        ?>

            .website .action_button_v2 .label,
            .content .ypdineBooker.onecol .content .search .button button,
            .content .ypdineBooker.onerow .content .search .button button,
            .content .block_form button.button,
            .content .block_form input.button,
            .content .block_form a.button,
            .custom_font.other.buttons {
                font-family: <?= $font_families['other'] ?>;
            }

        <?
    }

    // Apply if "labels" is in the list of other font targets
    if (in_array('labels', $font_families_targets['other'])){
        ?>

            .content .block_info_hours .item_label,
            .content .block_info_details .item_label,
            .content .block_specials_deals .list_item .item_day,
            .content .list_events .item_day,
            .content .block_group_details .field_block .label,
            .content .viplist_form .section .field .label,
            .content .block_contact_directions .label,
            .custom_font.other.labels {
                font-family: <?= $font_families['other'] ?>;
            }
            .content .viplist_form .section .question_consent .label {
                font-family: inherit;
            }

        <?
    }

    // Apply if "banners" is in the list of other font targets
    if (in_array('banners', $font_families_targets['other'])){
        ?>

            .website .page_banner_rotator .banner_slide .wrapper .caption,
            .website .page_banner .banner_wrapper .title_overlay .title,
            .custom_font.other.banners {
                font-family: <?= $font_families['other'] ?>;
            }

        <?
    }



}

?>