<?php
/**
 * NewsNation Dynamic Styles
 *
 * @package NewsNation
 */

function newsnation_dynamic_css()
{

    $newsnation_default = newsnation_get_default_theme_options();
    $logo_width_range = get_theme_mod('logo_width_range', $newsnation_default['logo_width_range']);

    $background_color = get_theme_mod('background_color');
    $site_title_font_size = get_theme_mod('site_title_font_size', $newsnation_default['site_title_font_size']);


    echo "<style type='text/css' media='all'>"; ?>

    .site-logo .custom-logo-link{
    max-width:  <?php echo esc_attr($logo_width_range); ?>px;
    }

    @media (min-width: 1200px) {
        .header-titles .site-title,
        .header-titles .custom-logo-name{
        font-size: <?php echo esc_attr($site_title_font_size); ?>px;
        }
    }

    .custom-background .sidr,
    .custom-background .header-searchbar-inner,
    .custom-background .offcanvas-wraper{
    background-color: #<?php echo esc_attr($background_color); ?>;
    }
    <?php echo "</style>";
}

add_action('wp_head', 'newsnation_dynamic_css', 100);

/**
 * Sanitizing Hex color function.
 */
function newsnation_sanitize_hex_color($color)
{

    if ('' === $color)
        return '';
    if (preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color))
        return $color;

}