<?php
function chic_lifestyle_dynamic_css() {
	
    wp_enqueue_style(
		'dynamic-css',
        get_stylesheet_uri(),
        array(),
        CHIC_LIFESTYLE_VERSION
	);

    function HexToBootstrapRgb($hex, $alpha = false) {
        $hex      = str_replace('#', '', $hex);
        $length   = strlen($hex);
        $rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
        $rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
        $rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
        if ($alpha) {
            $rgb['a'] = $alpha;
        }
        return (strval($rgb['r']) . ', ' . strval($rgb['g']) . ', ' . strval($rgb['b']));
    }

    $primary_color                  = get_theme_mod('primary_colors', '#f99595');
    $primary_color_rgb              = HexToBootstrapRgb($primary_color);
    $secondary_color                = get_theme_mod('secondary_colors', '#66d6d2');
    $secondary_color_rgb            = HexToBootstrapRgb($secondary_color);
    $dark_color                     = get_theme_mod('dark_color', '#000000');
    $dark_color_rgb                 = HexToBootstrapRgb($dark_color);
    $light_color                    = get_theme_mod('light_color', '#ffffff');
    $light_color_rgb                = HexToBootstrapRgb($light_color);
    $text_color                     = get_theme_mod('text_color', '#333333');
    $text_color_rgb                 = HexToBootstrapRgb($text_color);
    $secondary_text_color           = get_theme_mod('secondary_text_color', '#aaaaaa');
    $secondary_text_color_rgb       = HexToBootstrapRgb($secondary_text_color);
    $heading_title_color     		= get_theme_mod('heading_title_color', '#f99595');
    $heading_title_color_rgb        = HexToBootstrapRgb($heading_title_color);
    $footer_color                   = get_theme_mod('footer_color', '#f99595');
    $footer_color_rgb               = HexToBootstrapRgb($footer_color);
    $background_color               = get_theme_mod('background_color', '#ffffff');
    $background_color_rgb           = HexToBootstrapRgb($background_color);

    $site_title_color = get_theme_mod( 'site_title_color_option', '#000' );
    $site_title_size  = get_theme_mod('chic_lifestyle_logo_size', 30);
    $logo_size = $site_title_size * 2;
    $site_title_font_family = esc_attr( get_theme_mod( 'site_title_font_family', 'Rock Salt' ) );

    $font_family = esc_attr( get_theme_mod( 'font_family', 'Poppins' ) );
    $font_size = esc_attr( get_theme_mod( 'font_size', '13px' ) );
    $font_weight = absint( get_theme_mod( 'chic_lifestyle_font_weight', 400 ) );
    $line_height = absint( get_theme_mod( 'chic_lifestyle_line_height', 22 ) );

    $heading_font_family = esc_attr( get_theme_mod( 'heading_font_family', 'Poppins' ) );
    $heading_font_weight = esc_attr( get_theme_mod( 'heading_font_weight', 400 ) );


    $default_size = array(
        '1' =>  32,
        '2' =>  28,
        '3' =>  24,
        '4' =>  20,
        '5' =>  15,
        '6' =>  12,
    );

    for( $i = 1; $i <= 6 ; $i++ ) {
    	$heading[$i] = absint( get_theme_mod( 'chic_lifestyle_heading_' . $i . '_size', absint( $default_size[$i] ) ) );
    }


    $dynamic_css = "
    body{
        font: $font_weight $font_size/$line_height" . "px $font_family;
        color: $text_color;
        background-color: $background_color;
    }

    /* Primary Colors */

    /* Secondary Colors */

    /* Heading Links */
	h1 a,h1 a:hover,h1 a:active,h1 a:focus,h1 a:visited{color: $heading_title_color;}
    h2 a,h2 a:hover,h2 a:active,h2 a:focus,h2 a:visited{color: $heading_title_color;}
    h3 a,h3 a:hover,h3 a:active,h3 a:focus,h3 a:visited{color: $heading_title_color;}
    h4 a,h4 a:hover,h4 a:active,h4 a:focus,h4 a:visited{color: $heading_title_color;}
    h5 a,h5 a:hover,h5 a:active,h5 a:focus,h5 a:visited{color: $heading_title_color;}
    h6 a,h6 a:hover,h6 a:active,h6 a:focus,h6 a:visited{color: $heading_title_color;}

    :root {
        --primary-color: $primary_color !important;
        --primary-color_rgb: $primary_color_rgb;
        --secondary-color: $secondary_color;
        --secondary-color_rgb: $secondary_color_rgb;
        --hover-color: $secondary_color;
        --hover-color_rgb: $secondary_color_rgb;
        --dark-color: $dark_color;
        --dark-color_rgb: $dark_color_rgb;
        --light-color: $light_color;
        --light-color_rgb: $light_color_rgb;
        --text-color: $text_color;
        --text-color_rgb: $text_color_rgb;
        --text-secondary-color: $secondary_text_color;
        --text-secondary-color_rgb: $secondary_text_color_rgb;
        --footer-color: $footer_color;
        --footer-color_rgb: $footer_color_rgb;
        --background-color: $background_color;
        --background-color_rgb: $background_color_rgb;
        --font-size: $font_size;
        --font-weight: $font_weight;
        --line-height: {$line_height}px;
        --font-family: $font_family;
        --heading-font-family: $heading_font_family;
        --heading-font-weight: $heading_font_weight;
        --heading-title-color: $heading_title_color;
        --h1-font-size: $heading[1]px;
        --h2-font-size: $heading[2]px;
        --h3-font-size: $heading[3]px;
        --h4-font-size: $heading[4]px;
        --h5-font-size: $heading[5]px;
        --h6-font-size: $heading[6]px;
        --logo-size: {$logo_size}" . "px;
        --logo-font-size: {$site_title_size}" . "px;
        --logo-font-color: $site_title_color;
        --logo-font-family: $site_title_font_family;
        --sticky-header-height: 50px;
    }
    ";
    wp_add_inline_style( 'chic-lifestyle-style', $dynamic_css );
}
add_action( 'wp_enqueue_scripts', 'chic_lifestyle_dynamic_css' );
?>