<?php

/*-----------------------------------------------------------------------------------*/
/* Enqueue script and styles */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('green_environment_enqueue_scripts')) {

	function green_environment_enqueue_scripts() {

	    $green_environment_my_theme = wp_get_theme();
	    $green_environment_version = $green_environment_my_theme['Version'];

	    wp_enqueue_style(
			'bootstrap-css',
				get_template_directory_uri() . '/css/bootstrap.css',
				array(),'4.5.0'
			);

	    wp_enqueue_style( 'ecology-nature-style', get_template_directory_uri() . '/style.css' );

	    wp_enqueue_style( 'green-environment-style', get_stylesheet_directory_uri() . '/style.css', array('ecology-nature-woocommerce-css'), $green_environment_version );

	    wp_enqueue_style( 'green-environment-style', get_stylesheet_directory_uri() . '/style.css', array('ecology-nature-style'), $green_environment_version );

		if ( is_singular() ) wp_enqueue_script( 'comment-reply' );

	}

	add_action( 'wp_enqueue_scripts', 'green_environment_enqueue_scripts' );

}

/*-----------------------------------------------------------------------------------*/
/* Setup theme */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('green_environment_after_setup_theme')) {

	function green_environment_after_setup_theme() {

		if ( ! isset( $green_environment_content_width ) ) $green_environment_content_width = 900;

		add_theme_support( 'align-wide' );
		add_theme_support( 'woocommerce' );
		add_theme_support('title-tag');
		add_theme_support('automatic-feed-links');
		add_theme_support('post-thumbnails');
		add_theme_support( "responsive-embeds" );
		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'custom-background', array(
		  'default-color' => 'ffffff'
		));

		add_theme_support( 'custom-logo', array(
			'height'      => 70,
			'width'       => 70,
		) );

		add_theme_support( 'custom-header', array(
			'width' => 1920,
			'height' => 100,
			'flex-width' => true,
			'flex-height' => true,
		));

		add_theme_support( 'html5', array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );

		add_editor_style( array( '/css/editor-style.css' ) );
	}

	add_action( 'after_setup_theme', 'green_environment_after_setup_theme', 999 );

}

if (!function_exists('green_environment_widgets_init')) {

	function green_environment_widgets_init() {

		register_sidebar(array(

			'name' => esc_html__('Sidebar','green-environment'),
			'id'   => 'ecology-nature-sidebar',
			'description'   => esc_html__('This sidebar will be shown next to the content.', 'green-environment'),
			'before_widget' => '<div id="%1$s" class="sidebar-widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h4 class="title">',
			'after_title'   => '</h4>'

		));

		register_sidebar(array(

			'name' => esc_html__('Footer sidebar','green-environment'),
			'id'   => 'ecology-nature-footer-sidebar',
			'description'   => esc_html__('This sidebar will be shown next at the bottom of your content.', 'green-environment'),
			'before_widget' => '<div id="%1$s" class="col-lg-3 col-md-3 %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h4 class="title">',
			'after_title'   => '</h4>'

		));

	}

	add_action( 'widgets_init', 'green_environment_widgets_init' );

}

add_action( 'customize_register', 'green_environment_child_theme_override_global_color_default', 20 );
function green_environment_child_theme_override_global_color_default( $wp_customize ) {

    // Replace 'global_color' with the setting ID from the parent theme
    if ( $wp_customize->get_setting( 'ecology_nature_first_color' ) ) {
        $wp_customize->get_setting( 'ecology_nature_first_color' )->default = '#7abf18';
    }
}

function green_environment_remove_custom($wp_customize) {
  $wp_customize->remove_setting('ecology_nature_slider_button_2_link');
  $wp_customize->remove_setting('ecology_nature_second_color');
  $wp_customize->remove_setting('ecology_nature_third_color');
}
add_action( 'customize_register', 'green_environment_remove_custom', 1000 );


function green_environment_template_setup() {

/*-----------------------------------------------------------------------------------*/
/* Customizer */
/*-----------------------------------------------------------------------------------*/

if ( class_exists("Kirki")){

	// FEATURES SECTION

	Kirki::add_section( 'green_environment_features_section', array(
		'title'          => esc_html__( 'Our Features Settings', 'green-environment' ),
		'description'    => esc_html__( 'You have to select category to show features.', 'green-environment' ),
		'panel'          => 'ecology_nature_panel_id',
		'priority'       => 170,
	) );

  	Kirki::add_field( 'theme_config_id', [
		'type'        => 'custom',
		'settings'    => 'green_environment_enable_heading',
		'section'     => 'green_environment_features_section',
			'default'         => '<h3 style="color: #2271b1; padding:10px; background:#fff; margin:0; border-left: solid 5px #2271b1; ">' . __( 'Enable / Disable Features',  'green-environment' ) . '</h3>',
		'priority'    => 10,
	] );

  	Kirki::add_field( 'theme_config_id', [
		'type'        => 'switch',
		'settings'    => 'green_environment_features_section_enable',
		'label'       => esc_html__( 'Section Enable / Disable',  'green-environment' ),
		'section'     => 'green_environment_features_section',
		'default'     => false,
		'priority'    => 10,
		'choices'     => [
			'on'  => esc_html__( 'Enable',  'green-environment' ),
			'off' => esc_html__( 'Disable',  'green-environment' ),
		],
	] );

  	Kirki::add_field( 'theme_config_id', [
		'type'        => 'custom',
		'settings'    => 'green_environment_features_heading',
		'section'     => 'green_environment_features_section',
			'default'         => '<h3 style="color: #2271b1; padding:10px; background:#fff; margin:0; border-left: solid 5px #2271b1; ">' . __( 'Features Section ',  'green-environment' ) . '</h3>',
		'priority'    => 10,
	] );


	Kirki::add_field( 'theme_config_id', [
	    'type'        => 'number',
	    'settings'    => 'green_environment_features_counter',
	    'label'       => esc_html__( 'Features Counter Section',  'green-environment' ),
	    'section'     => 'green_environment_features_section',
	    'default'     => 0,
	    'choices'     => [
	        'min'  => 0,
	        'max'  => 3,
	        'step' => 1,
	    ],
	] );

  	$green_environment_features_image = get_theme_mod('green_environment_features_counter','');
    for ( $i = 1; $i <= $green_environment_features_image; $i++ ) :

		Kirki::add_field( 'theme_config_id', [
			'type'     => 'dashicons',
			'settings' => 'green_environment_features_icon_setting'.$i,
			'label'    => esc_html__( 'Features Icon ', 'green-environment' ).$i,
			'section'  => 'green_environment_features_section',
			'priority' => 10,
	    ] );

		Kirki::add_field( 'theme_config_id', [
			'type'     => 'text',
			'settings' => 'green_environment_features_title_text'.$i,
			'label'    => esc_html__( 'Features Title Text ', 'green-environment' ).$i,
			'section'  => 'green_environment_features_section',
			'priority' => 10,
    	] );

	    Kirki::add_field( 'theme_config_id', [
			'type'     => 'textarea',
			'settings' => 'green_environment_features_content_text'.$i,
			'label'    => esc_html__( 'Features Content ', 'green-environment' ).$i,
			'section'  => 'green_environment_features_section',
			'priority' => 10,
	    ] );

	endfor;
}

require get_stylesheet_directory() . '/core/includes/importer/config.php';

/*-----------------------------------------------------------------------------------*/
/* Enqueue Dark Mode Style */
/*-----------------------------------------------------------------------------------*/
function green_environment_dark_mode() {

$green_environment_custom_css = '';

$ecology_nature_is_dark_mode_enabled = get_theme_mod( 'ecology_nature_is_dark_mode_enabled', false );

if ( $ecology_nature_is_dark_mode_enabled ) {

    $green_environment_custom_css .= 'body,.fixed-header,tr:nth-child(2n+2),.header,.page-template-frontpage .top-header,.page-template-frontpage #site-navigationn,.featuress-content,.header-box {';
    $green_environment_custom_css .= 'background: #000;';
    $green_environment_custom_css .= '}';

    $green_environment_custom_css .= 'body,h1,h2,h3,h4,h5,p,#main-menu ul li a,.woocommerce .woocommerce-ordering select, .woocommerce form .form-row input.input-text, .woocommerce form .form-row textarea,a,#trending h2{';
    $green_environment_custom_css .= 'color: #fff;';
    $green_environment_custom_css .= '}';

    $green_environment_custom_css .= 'a.wc-block-components-product-name, .wc-block-components-product-name,.wc-block-components-totals-footer-item .wc-block-components-totals-item__value,
.wc-block-components-totals-footer-item .wc-block-components-totals-item__label,
.wc-block-components-totals-item__label,.wc-block-components-totals-item__value,
.wc-block-components-product-metadata .wc-block-components-product-metadata__description>p,
.is-medium table.wc-block-cart-items .wc-block-cart-items__row .wc-block-cart-item__total .wc-block-components-formatted-money-amount,
.wc-block-components-quantity-selector input.wc-block-components-quantity-selector__input,
.wc-block-components-quantity-selector .wc-block-components-quantity-selector__button,
.wc-block-components-quantity-selector,table.wc-block-cart-items .wc-block-cart-items__row .wc-block-cart-item__quantity .wc-block-cart-item__remove-link,
.wc-block-components-product-price__value.is-discounted,del.wc-block-components-product-price__regular,.logo a,.logo span,li.menu-item-has-children:after,h1.woocommerce-products-header__title.page-title,h2.woocommerce-loop-product__title,h1.product_title.entry-title,div#tab-description h2,section.related.products h2,h2.woocommerce-Reviews-title,h2#reply-title,h2.comments-title,.pagination .nav-links a, .pagination .nav-links span.current, .ecology-nature-pagination a span, .ecology-nature-pagination span.current{';
    $green_environment_custom_css .= 'color: #fff !important;';
    $green_environment_custom_css .= '}';

    $green_environment_custom_css .= 'h5.product-text a,#featured-product p.price,.card-header a,.comment-content.card-block p,.blog_box h3 a,.pagination .nav-links a, .pagination .nav-links span.current, .ecology-nature-pagination a span, .ecology-nature-pagination span.current{';
    $green_environment_custom_css .= 'color: #000 !important';
    $green_environment_custom_css .= '}';

	$green_environment_custom_css .= '.post-box{';
    $green_environment_custom_css .= '    border: 1px solid rgb(229 229 229 / 48%)';
    $green_environment_custom_css .= '}';
}

    wp_add_inline_style( 'green-environment-style',$green_environment_custom_css );
    wp_add_inline_style( 'green-environment-woocommerce-css',$green_environment_custom_css );

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

if ( ! defined( 'ECOLOGY_NATURE_BUY_NOW' ) ) {
	define( 'ECOLOGY_NATURE_BUY_NOW', 'https://www.misbahwp.com/products/environmental-wordpress-theme' );
}
if ( ! defined( 'ECOLOGY_NATURE_THEME_NAME' ) ) {
	define( 'ECOLOGY_NATURE_THEME_NAME', esc_html__( 'Environment PRO', 'green-environment' ));
}
if (! defined( 'ECOLOGY_NATURE_DOCS_FREE' ) ){
define('ECOLOGY_NATURE_DOCS_FREE',__('https://demo.misbahwp.com/docs/green-environment-free-docs/','green-environment'));
}
if (! defined( 'ECOLOGY_NATURE_DOCS_PRO' ) ){
define('ECOLOGY_NATURE_DOCS_PRO',__('https://demo.misbahwp.com/docs/green-environment-pro-docs','green-environment'));
}
if (! defined( 'ECOLOGY_NATURE_SUPPORT_FREE' ) ){
define('ECOLOGY_NATURE_SUPPORT_FREE',__('https://wordpress.org/support/theme/green-environment','green-environment'));
}
if (! defined( 'ECOLOGY_NATURE_REVIEW_FREE' ) ){
define('ECOLOGY_NATURE_REVIEW_FREE',__('https://wordpress.org/support/theme/green-environment/reviews/#new-post','green-environment'));
}
if (! defined( 'ECOLOGY_NATURE_DEMO_PRO' ) ){
define('ECOLOGY_NATURE_DEMO_PRO',__('https://demo.misbahwp.com/green-environment/','green-environment'));
}
if ( ! defined( 'ECOLOGY_NATURE_DEMO_LINK_URL' ) ) {
    define( 'ECOLOGY_NATURE_DEMO_LINK_URL', 'https://demo.misbahwp.com/green-environment/' );
}
if (! defined( 'ECOLOGY_NATURE_FREE_THEME_NAME' ) ){
define('ECOLOGY_NATURE_FREE_THEME_NAME',__('Green Environment PRO','ecology-nature'));
}

}
add_action('after_setup_theme', 'green_environment_template_setup');

add_action( 'after_setup_theme', function () {
    // If the parent used a different priority than 5, detect it first:
    $prio = has_action( 'after_setup_theme', 'ecology_nature_template_include_wizard' );
    if ( false !== $prio ) {
        remove_action( 'after_setup_theme', 'ecology_nature_template_include_wizard', $prio );
    } else {
        // If you're unsure, also try removing at 5 explicitly:
        remove_action( 'after_setup_theme', 'ecology_nature_template_include_wizard', 5 );
    }
}, 0 );
