<?php
/**
 * Solar Panels functions and definitions
 *
 * @package Solar Panels
 */

if ( ! function_exists( 'solar_panels_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which runs
 * before the init hook. The init hook is too late for some features, such as indicating
 * support post thumbnails.
 */
function solar_panels_setup() {
	global $solar_panels_content_width;
	if ( ! isset( $solar_panels_content_width ) )
		$solar_panels_content_width = 680;

	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'wp-block-styles');
	add_theme_support( 'align-wide' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'custom-logo', array(
		'height'      => 100,
		'width'       => 100,
		'flex-height' => true,
	) );
	add_theme_support( 'custom-background', array(
		'default-color' => 'ffffff'
	) );
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );
	add_editor_style( 'editor-style.css' );
}
endif; // solar_services_setup
add_action( 'after_setup_theme', 'solar_panels_setup' );

function solar_panels_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'solar-panels' ),
		'description'   => __( 'Appears on blog page sidebar', 'solar-panels' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	$solar_services_widget_areas = get_theme_mod('solar_services_footer_widget_areas', '4');
	for ($solar_services_i=1; $solar_services_i <= 4; $solar_services_i++) {
		register_sidebar( array(
			'name'          => __( 'Footer Widget ', 'solar-panels' ) . $solar_services_i,
			'id'            => 'footer-' . $solar_services_i,
			'description'   => '',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );
	}
}
add_action( 'widgets_init', 'solar_panels_widgets_init' );

add_action( 'wp_enqueue_scripts', 'solar_panels_enqueue_styles' );
function solar_panels_enqueue_styles() {
    $parenthandle = 'solar-panels-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    $theme = wp_get_theme();
    wp_enqueue_style( $parenthandle, esc_url(get_template_directory_uri()) . '/style.css',
        array(),  // if the parent theme code has a dependency, copy it to here
        $theme->parent()->get('Version')
    );
    wp_enqueue_style( 'solar-panels-child-style', get_stylesheet_uri(),
        array( $parenthandle ),
        $theme->get('Version') // this only works if you have Version in the style header
    );
	require get_theme_file_path( 'inc/color-scheme/custom-color-control.php' );
	wp_add_inline_style( 'solar-panels-child-style',$solar_panels_color_scheme_css );
}

// customizer css
function solar_panels_enqueue_customizer_css() {
    wp_enqueue_style( 'solar_panels-customizer-css', get_stylesheet_directory_uri() . '/css/customize-controls.css' );
}
add_action( 'customize_controls_print_styles', 'solar_panels_enqueue_customizer_css' );

function solar_panels_scripts() {

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	// font-family
	$solar_panels_headings_font = esc_html(get_theme_mod('solar_panels_headings_fonts'));
	$solar_panels_body_font = esc_html(get_theme_mod('solar_panels_body_fonts'));

	if ($solar_panels_headings_font) {
	    wp_enqueue_style('solar-panels-headings-fonts', 'https://fonts.googleapis.com/css?family=' . urlencode($solar_panels_headings_font));
	} else {
	    wp_enqueue_style('roboto-headings', 'https://fonts.googleapis.com/css?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900');
	}

	if ($solar_panels_body_font) {
	    wp_enqueue_style('solar-panels-source-body', 'https://fonts.googleapis.com/css?family=' . urlencode($solar_panels_body_font));
	} else {
	    wp_enqueue_style('roboto-body', 'https://fonts.googleapis.com/css?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900');
	}

}
add_action( 'wp_enqueue_scripts', 'solar_panels_scripts' );

add_action( 'customize_register', 'solar_panels_customize_register', 11 );
function solar_panels_customize_register() {
	global $wp_customize;
	$wp_customize->remove_section( 'solar_services_global_color' );

	$wp_customize->remove_setting( 'solar_services_blogboxbg_color' );
	$wp_customize->remove_control( 'solar_services_blogboxbg_color' );

	$wp_customize->remove_setting( 'solar_services_blogdescription_color' );
	$wp_customize->remove_control( 'solar_services_blogdescription_color' );

	$wp_customize->remove_setting( 'solar_services_blogebtntxt_color' );
	$wp_customize->remove_control( 'solar_services_blogebtntxt_color' );

	$wp_customize->remove_setting( 'solar_services_blogebtnbg_color' );
	$wp_customize->remove_control( 'solar_services_blogebtnbg_color' );

	$wp_customize->remove_section( 'solar_services_feature_section' );
}

// Customizer Section
function solar_panels_customizer ( $wp_customize ) {

   //Global Color
   $wp_customize->add_section('solar_panels_global_color', array(
	   'title'    => __('Manage Global Color Section', 'solar-panels'),
	   'panel'    => 'solar_services_panel_area',
   ));
   $wp_customize->add_setting('solar_panels_first_color', array(
	   'default'           => '',
	   'sanitize_callback' => 'sanitize_hex_color',
   ));
   $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'solar_panels_first_color', array(
	   'label'    => __('Theme Color', 'solar-panels'),
	   'section'  => 'solar_panels_global_color',
	   'settings' => 'solar_panels_first_color',
   )));	
   $wp_customize->add_setting('solar_panels_second_color', array(
	   'default'           => '',
	   'sanitize_callback' => 'sanitize_hex_color',
   ));
   $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'solar_panels_second_color', array(
	   'label'    => __('Theme Color', 'solar-panels'),
	   'section'  => 'solar_panels_global_color',
	   'settings' => 'solar_panels_second_color',
   )));	
   $wp_customize->add_setting( 'solar_panels_global_color_settings_upgraded_features',array(
	'sanitize_callback' => 'sanitize_text_field'
   )); 
   $wp_customize->add_control('solar_panels_global_color_settings_upgraded_features', array(
 	 'type'=> 'hidden',
	 'description' => "<span class='customizer-upgraded-features'>Unlock Premium Customization Features:
		 <a target='_blank' href='". esc_url(SOLAR_SERVICES_PREMIUM_PAGE) ." '>Upgrade to Pro</a></span>",
	 'section' => 'solar_panels_global_color'
  ));   
}
add_action( 'customize_register', 'solar_panels_customizer' );

function solar_panels_setup_theme() {
	if ( ! defined( 'SOLAR_SERVICES_SUPPORT' ) ) {
	define('SOLAR_SERVICES_SUPPORT',__('https://wordpress.org/support/theme/solar-panels/','solar-panels'));
	}
	if ( ! defined( 'SOLAR_SERVICES_REVIEW' ) ) {
	define('SOLAR_SERVICES_REVIEW',__('https://wordpress.org/support/theme/solar-panels/reviews/','solar-panels'));
	}
	if ( ! defined( 'SOLAR_SERVICES_PRO_DEMO' ) ) {
	define('SOLAR_SERVICES_PRO_DEMO',__('https://live.theclassictemplates.com/solar-energy/','solar-panels'));
	}
	if ( ! defined( 'SOLAR_SERVICES_THEME_PAGE' ) ) {
	define('SOLAR_SERVICES_THEME_PAGE',__('https://www.theclassictemplates.com/collections/best-wordpress-templates','solar-panels'));
	}
	if ( ! defined( 'SOLAR_SERVICES_PREMIUM_PAGE' ) ) {
	define('SOLAR_SERVICES_PREMIUM_PAGE',__('https://www.theclassictemplates.com/products/solar-panels-wordpress-theme','solar-panels'));
	}
	if ( ! defined( 'SOLAR_SERVICES_THEME_DOCUMENTATION' ) ) {
	define('SOLAR_SERVICES_THEME_DOCUMENTATION',__('https://live.theclassictemplates.com/demo/docs/solar-panels-free/','solar-panels'));
	}
	if ( ! defined( 'SOLAR_SERVICES_BUNDLE_PAGE' ) ) {
		define('SOLAR_SERVICES_BUNDLE_PAGE',__('https://www.theclassictemplates.com/products/wordpress-theme-bundle','solar-panels'));
	}
}
add_action( 'after_setup_theme', 'solar_panels_setup_theme' );

if ( ! function_exists( 'solar_services_the_custom_logo' ) ) :
	/**
	 * Displays the optional custom logo.
	 *
	 * Does nothing if the custom logo is not available.
	 *
	 * @since solar-panels
	 */
	function solar_services_the_custom_logo() {
		if ( function_exists( 'the_custom_logo' ) ) {
			// Check if custom logo is set via the customizer
			if ( has_custom_logo() ) {
				the_custom_logo();
			} else {
				// If no custom logo, display the logo from the child theme directory
				echo "<a href='" . esc_url( home_url() ) . "' rel='home'>
						<img src='" . esc_url( get_stylesheet_directory_uri() ) . "/images/Logo.png' alt='" . esc_attr__( 'Solar Panels logo', 'solar-panels' ) . "' />
					  </a>";
			}
		}
	}
endif;


add_filter( 'solar_services_demo_content_path', function( $solar_servicess_center_default_path ) {
    $solar_servicess_center_child_path = get_stylesheet_directory() . '/inc/demo-content.php';

    if ( file_exists( $solar_servicess_center_child_path ) ) {
        return $solar_servicess_center_child_path;
    }

    return $solar_servicess_center_default_path; 
});

// Load additional admin styles for the child theme
function solar_servicess_center_admin_enqueue_scripts() {
    wp_enqueue_style( 'solar-panels-admin-style', get_stylesheet_directory_uri() . '/css/addon.css' );
}
add_action( 'admin_enqueue_scripts', 'solar_servicess_center_admin_enqueue_scripts' );