<?php
if ( ! function_exists( 'nextpage_dynamic_styles' ) ) {

	function nextpage_dynamic_styles() {

		ob_start();


		/*------------------------------------------------------------------------------------
		 * body font
		------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'body_font_enable', 0 ) ) :

			$nextpage_body_font = nextpage_get_option( 'nextpage_body_font' );
			$font_weight = isset( $nextpage_body_font['font-weight'] ) ? $nextpage_body_font['font-weight'] : "normal";
			?>

            body{
            font-family:<?php echo esc_attr( $nextpage_body_font['font-family'] ); ?>;
            font-weight:<?php echo esc_attr( $font_weight ); ?>;
            font-size:<?php echo esc_attr( $nextpage_body_font['font-size'] ); ?>px;
            }

		<?php

		endif;

		/*------------------------------------------------------------------------------------
		 * body font
		------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'heading_font_enable', 0 ) ) :

			$nextpage_heading_font = nextpage_get_option( 'heading_font' );
			$font_weight = isset( $nextpage_heading_font['font-weight'] ) ? $nextpage_heading_font['font-weight'] : "normal";
			?>

            h1,h2,h3,h4,h5,h6{
            font-family:<?php echo esc_attr( $nextpage_heading_font['font-family'] ); ?>;
            font-weight:<?php echo esc_attr( $font_weight ); ?>;
            }

		<?php

		endif;


		/*------------------------------------------------------------------------------------
		 * taxonomy color
		------------------------------------------------------------------------------------ */

		$nextpage_taxonomy            = get_terms( 'category', 'orderby=count&hide_empty=0' );

		foreach ( $nextpage_taxonomy as $term ) :

			$nextpage_cat_meta = get_term_meta( $term->term_id, 'nextpage', true ); //color
			$nextpage_cat_color       = ( isset( $nextpage_cat_meta['catcolor'] ) ? $nextpage_cat_meta['catcolor'] : '#097bed' );
			$nextpage_cat_hover_color = ( isset( $nextpage_cat_meta['cathovercolor'] ) ? $nextpage_cat_meta['cathovercolor'] : '#fff' );
			$nextpage_bg_color        = ( isset( $nextpage_cat_meta['bgcolor'] ) ? $nextpage_cat_meta['bgcolor'] : '#e6f2fd' );
			$nextpage_hover_bg_color  = ( isset( $nextpage_cat_meta['bg_hover_color'] ) ? $nextpage_cat_meta['bg_hover_color'] : '#e6f2fd' );

			?>

            .<?php echo esc_attr( str_replace( ' ', '', $term->slug ) ); ?> {
            background: <?php echo sanitize_hex_color( $nextpage_bg_color ); ?>;
            color: <?php echo sanitize_hex_color( $nextpage_cat_color ); ?>;
            }

            .<?php echo esc_attr( str_replace( ' ', '', $term->slug ) ); ?>:hover{
            background:<?php echo sanitize_hex_color( $nextpage_hover_bg_color ); ?>;
            color: <?php echo sanitize_hex_color( $nextpage_cat_hover_color ); ?>;
            }

		<?php endforeach;

		/*------------------------------------------------------------------------------------
		* social icon  color
	   ------------------------------------------------------------------------------------ */
		$nextpage_top_social_icon = nextpage_get_option( 'topbar-social-icon' ); //check social icon
		if ( is_array( $nextpage_top_social_icon ) ) :
			foreach ( $nextpage_top_social_icon as $item ) { ?>
                .bg<?php echo esc_attr( ltrim( $item['color'], '#' ) ); ?>{
                background:<?php echo esc_attr( $item['color'] ); ?>;
                }
			<?php } endif;

		$nextpage_footer_social_icon = nextpage_get_option( 'footer-social-icon' ); //footer social icon
		if ( is_array( $nextpage_top_social_icon ) ) :
			foreach ( $nextpage_footer_social_icon as $item ) { ?>
                .bg<?php echo esc_attr( ltrim( $item['color'], '#' ) ); ?>{
                background:<?php echo esc_attr( $item['color'] ); ?>;
                }
			<?php } endif;

		/*------------------------------------------------------------------------------------
		  blog page spacing
		 ------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'blog_spacing_enable', 0 ) ) :

			?>

            .nextpage-blog-page{
            margin-top:<?php echo esc_attr( nextpage_get_option( 'blog_top_padding' ) ); ?>px;
            margin-bottom:<?php echo esc_attr( nextpage_get_option( 'blog_bottom_padding' ) ); ?>px;
            }

		<?php

		endif;

		/*------------------------------------------------------------------------------------
		 blog details page spacing
		------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'blog_details_spacing_enable', 0 ) ) :

			?>

            .nextpage-blog-details{
            margin-top:<?php echo esc_attr( nextpage_get_option( 'single_top_padding' ) ); ?>px;
            margin-bottom:<?php echo esc_attr( nextpage_get_option( 'single_bottom_padding' ) ); ?>px;
            }

		<?php

		endif;


		/*------------------------------------------------------------------------------------
		  archive page spacing
		 ------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'archive_page_spacing_enable', 0 ) ) :

			?>

            .nextpage-archive-page{
            margin-top:<?php echo esc_attr( nextpage_get_option( 'archive_top_padding' ) ); ?>px;
            margin-bottom:<?php echo esc_attr( nextpage_get_option( 'archive_bottom_padding' ) ); ?>px;
            }

		<?php

		endif;

		/*------------------------------------------------------------------------------------
		 search page spacing
		------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'search_page_spacing_enable', 0 ) ) :

			?>

            .search-archive-page{
            margin-top:<?php echo esc_attr( nextpage_get_option( 'search_top_padding' ) ); ?>px;
            margin-bottom:<?php echo esc_attr( nextpage_get_option( 'search_bottom_padding' ) ); ?>px;
            }

		<?php

		endif;

		/*------------------------------------------------------------------------------------
		  footer top spacing
		------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'footer_spacing', 0 ) ) :

			?>

            .nextpage-footer-top{
            margin-top:<?php echo esc_attr( nextpage_get_option( 'footer_top_spacing' ) ); ?>px;
            margin-bottom:<?php echo esc_attr( nextpage_get_option( 'footer_bottom_spacing' ) ); ?>px;
            }

		<?php

		endif;

		/*------------------------------------------------------------------------------------
		  footer bottom spacing
		------------------------------------------------------------------------------------ */

		if ( 1 == nextpage_get_option( 'copyright_area_spacing', 0 ) ) :

			?>

            .footer-bottom{
            padding-top:<?php echo esc_attr( nextpage_get_option( 'copyright_area_top_spacing' ) ); ?>px;
            padding-bottom:<?php echo esc_attr( nextpage_get_option( 'copyright_area_bottom_spacing' ) ); ?>px;
            }

		<?php

		endif;

		/*------------------------------------------------------------------------------------
		  From customizer
	   ------------------------------------------------------------------------------------ */

		//primary color

		if ( ! empty( nextpage_get_customize_option( 'main_color' ) ) ) :
			?>
            :root {
            --main-color:  <?php echo esc_attr( nextpage_get_customize_option( 'main_color' ) ); ?>;
            }
		<?php endif;

		$output = ob_get_clean();

		return $output;


	} //end  nextpage_dynamic_styles

} //endif


function nextpage_style_method() {

	$custom_css = nextpage_dynamic_styles();

	wp_add_inline_style( 'nextpage-style', $custom_css );
}

add_action( 'wp_enqueue_scripts', 'nextpage_style_method' );



   