<?php

function edify_fonts_url(){
    $fonts_url		 = '';
    $fonts = array();
    $subsets   = 'latin,latin-ext';

    if ($fonts) {
        $query_args = array(
            'family'  => urlencode( implode( '|',$fonts ) ),
            'subset'  => urlencode( 'latin,latin-ext' ),
            'display' => urlencode( 'fallback' ),
        );
 
        $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    }
 
    return esc_url_raw($fonts_url);
 }



//  Theme custom style

 
function theme_custom_css() {
    $primary_color = get_theme_mod('primary_color');
   

    $secondary_color = get_theme_mod('secondary_color');
    $heading_color = get_theme_mod('heading_color');
    $font_color = get_theme_mod('font_color');
    $body_bg = get_theme_mod('body_bg');

    //    Typography Option
    $body_font = get_theme_mod('body_font',[]);
    $heading_font = get_theme_mod('heading_font',[]);

    $menu_font = get_theme_mod('menu_font',[]);

    $h1_font = get_theme_mod('h1_font',[]);
    $h2_font = get_theme_mod('h2_font',[]);
    $h3_font = get_theme_mod('h3_font',[]);
    $h4_font = get_theme_mod('h4_font',[]);



    $page_bg_color = get_theme_mod('page_bg_color');
    $page_header_color= get_theme_mod('page_header_color');

    $topbar_bg_color= get_theme_mod('topbar_bg_color');
    $topbar_font_color= get_theme_mod('topbar_font_color');
    $top_social_icon_color= get_theme_mod('top_social_icon_color');
    $top_social_hover_color= get_theme_mod('top_social_hover_color');


    $top_social_icon_bg_color = get_theme_mod('top_social_icon_bg_color');
    $top_social_icon_hover_bg= get_theme_mod('top_social_icon_hover_bg');
    $front_banner_bg= get_theme_mod('front_banner_bg');


    $custom_css = '';

    
   
if(class_exists( 'kirki' )){

    if(!empty( $heading_font)){
        $custom_css .= '
              :root{
               --theme-heading-font:'.esc_attr($heading_font['font-family']).';
            }
        ';
    }

    if(!empty( $body_font)){
        $custom_css .= '
          

             :root{
                --theme-secondary-font:'.esc_attr($body_font['font-family']).';
            }

        ';
    }


    if(!empty(  $h1_font['font-size'])){
        $custom_css .= '
            h1{
                font-size:'.esc_attr( $h1_font['font-size']).';
            }
        ';
    }

    if(!empty($h1_font['line-height'])){
        $custom_css .= '
            h1{
                line-height:'.esc_attr( $h1_font['line-height']).';
            }
        ';
    }
    if(!empty(  $h2_font['font-size'])){
        $custom_css .= '
            h2{
                font-size:'.esc_attr( $h2_font['font-size']).';
            }
        ';
    }

    if(!empty($h2_font['line-height'])){
        $custom_css .= '
            h2{
                line-height:'.esc_attr( $h2_font['line-height']).';
            }
        ';
    }

    if(!empty( $h3_font['font-size'])){
        $custom_css .= '
            h3{
                font-size:'.esc_attr( $h3_font['font-size']).';
            }
        ';
    }
     if(!empty($h3_font['line-height'])){
        $custom_css .= '
            h3{
                line-height:'.esc_attr( $h3_font['line-height']).';
            }
        ';
    }
    
    if(!empty( $h4_font['font-size'])){
        $custom_css .= '
            h4{
                font-size:'.esc_attr( $h4_font['font-size']).';
            }
        ';
    }

    if(!empty($h4_font['line-height'])){
        $custom_css .= '
            h4{
                line-height:'.esc_attr( $h4_font['line-height']).';
            }
        ';
    }


    if(!empty( $menu_font)){
        $custom_css .= '
            .site-navbar.ms-auto ul li a{
                font-family : '.esc_attr($menu_font['font-family']).'; 
                font-size:'.esc_attr($menu_font['font-size']).'; 
                font-weight: '.esc_attr($menu_font['variant']).';
                line-height: '.esc_attr($menu_font['line-height']).';
                text-transform: '.esc_attr($menu_font['text-transform']).';
            }
    
        ';
    }
    

 
    if(!empty( $page_header_color)){
        $custom_css .= '
            .page-header{
                background:'.esc_attr($page_header_color).';
            }
        ';
    }

    
    if(!empty( $page_bg_color)){
        $custom_css .= '
            .page-wrapper {
                background:'.esc_attr($page_bg_color).';
            }
        ';
    }
        
    
    if(!empty( $topbar_bg_color)){
        $custom_css .= '
            .header-topbar-1{
                background:'.esc_attr($topbar_bg_color).';
            }
        ';
    }

    
    if(!empty( $topbar_font_color)){
        $custom_css .= '
            .top-info, .top-info a , .top-info span {
                color:'.esc_attr($topbar_font_color).';
            }
        ';
    }
    if(!empty( $front_banner_bg)){
        $custom_css .= '
            .front-banner-section{
                background:'.esc_attr($front_banner_bg).';
            }
        ';
    }

    if(!empty( $top_social_icon_color)){
        $custom_css .= '
            .header-topbar-right a{
                color:'.esc_attr($top_social_icon_color).';
            }
        ';
    }

    if(!empty( $top_social_icon_bg_color)){
        $custom_css .= '
            .header-topbar-right a{
                background:'.esc_attr($top_social_icon_bg_color).';
            }
        ';
    }
    if(!empty( $top_social_icon_hover_bg)){
        $custom_css .= '
            .header-topbar-right a:hover{
                background:'.esc_attr($top_social_icon_hover_bg).';
            }
        ';
    }

    
    if(!empty( $primary_color)){
        $custom_css .= '
            :root {
                --theme-primary-color:'.esc_attr($primary_color).';
                --theme-font-color:'.esc_attr($primary_color).';
            }
        ';
    }
    


        if(!empty( $secondary_color)){
            $custom_css .= '

                :root {
                    --theme-secondary-color:'.esc_attr($secondary_color).';        
                }
            ';
        }

        
        if(!empty( $heading_color)){
            $custom_css .= '

            .h1, .h2, .h3, .h4, .h5, .h6, h1, h2, h3, h4, h5, h6{
                color:'.esc_attr($heading_color).';
            }
            ';
        }


        if(!empty( $font_color)){
            $custom_css .= '
                p,body{
                    color:'.esc_attr($font_color).';
                }
            ';
        }

    }
    

	wp_enqueue_style(
		'custom-theme-style',
		get_template_directory_uri() . '/assets/css/theme-style.css'
	);
    
    wp_add_inline_style( 'custom-theme-style', $custom_css );
}
    
add_action( 'wp_enqueue_scripts', 'theme_custom_css' );


?>
