<?php

/**
 * Function for changing links and color hue. -- START
 */
function kindrex_color_changer( $wp_customize ) {
	$wp_customize->add_section(
		'kindrex-coloring-section',
		array(
			'title'    => __( 'Theme Colors', 'kindrex' ),
			'priority' => '80',
		)
	);
	/**
	 * Background Color Section - START
	 */
	$wp_customize->add_setting(
		'kindrex_bg_color',
		array(
			'default'           => '#cccccc',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize,
			'kindrex_bg_color',
			array(
				'label'       => __( 'Background Color:', 'kindrex' ),
				'section'     => 'kindrex-coloring-section',
				'description' => esc_html__( 'Site background color.', 'kindrex' ),
				'settings'    => 'kindrex_bg_color',
			)
		)
	);
	/**
	 * Background Color Section - END
	 */

	/**
	 * Main Text Section - START
	 */
	$wp_customize->add_setting(
		'kindrex_maintext_color',
		array(
			'default'           => '#7f7f7f',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize,
			'kindrex_maintext_color',
			array(
				'label'       => __( 'Global Text Color:', 'kindrex' ),
				'section'     => 'kindrex-coloring-section',
				'description' => esc_html__( 'Base text that are not links.', 'kindrex' ),
				'settings'    => 'kindrex_maintext_color',
			)
		)
	);
	/**
	 * Main Text Section - END
	 */

	$wp_customize->add_setting(
		'kindrex_links_color',
		array(
			'default'           => '#2377ed',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize,
			'kindrex_links_color',
			array(
				'label'       => __( 'Link Color:', 'kindrex' ),
				'section'     => 'kindrex-coloring-section',
				'description' => esc_html__( 'Change the color of anchor links.', 'kindrex' ),
				'settings'    => 'kindrex_links_color',
			)
		)
	);

	/**
	 * Link Hover Section - START
	 */
	$wp_customize->add_setting(
		'kindrex_links_hover_color',
		array(
			'default'           => '#001489',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize,
			'kindrex_links_hover_color',
			array(
				'label'       => __( 'Link Hover Color:', 'kindrex' ),
				'section'     => 'kindrex-coloring-section',
				'description' => esc_html__( 'Change the color of anchor hover.', 'kindrex' ),
				'settings'    => 'kindrex_links_hover_color',
			)
		)
	);
	/**
	 * Link Hover Section - END
	 */

	/**
	 * Mega Menu Link Color Section - START
	 */
	$wp_customize->add_control(
		'labels1',
		array(
			'type'        => 'button',
			'settings'    => array(),
			'label'       => __( 'Menu Link Color:', 'kindrex' ),
			'description' => esc_html__( 'Link color for mega menu.', 'kindrex' ),
			'priority'    => 10,
			'section'     => 'kindrex-coloring-section',
			'input_attrs' => array(
				'value'   => __( 'Get pro for this feature!', 'kindrex' ),
				'class'   => 'button-secondary',
				'onclick' => "window.open('https://www.designwicked.com/store/premium-kindrex', '_blank')",
			),
		)
	);
	/**
	 * Mega Menu Link Color Section - END
	 */

	/**
	 * Mega Menu Link Hover Color Section - START
	 */
	$wp_customize->add_control(
		'labels2',
		array(
			'type'        => 'button',
			'settings'    => array(),
			'label'       => __( 'Menu Link Hover Color:', 'kindrex' ),
			'description' => esc_html__( 'Hover link color for menu.', 'kindrex' ),
			'priority'    => 10,
			'section'     => 'kindrex-coloring-section',
			'input_attrs' => array(
				'value'   => __( 'Get pro for this feature!', 'kindrex' ),
				'class'   => 'button-secondary',
				'onclick' => "window.open('https://www.designwicked.com/store/premium-kindrex', '_blank')",
			),
		)
	);

	/**
	 * Mega Menu Link Hover Color Section - END
	 */

	/**
	 * Side Widget Title Section - START
	 */
	$wp_customize->add_control(
		'labels4',
		array(
			'type'        => 'button',
			'settings'    => array(),
			'label'       => __( 'Side/Top/Bottom Widget Title Color:', 'kindrex' ),
			'description' => esc_html__( 'Widget title color for outer blocks.', 'kindrex' ),
			'priority'    => 10,
			'section'     => 'kindrex-coloring-section',
			'input_attrs' => array(
				'value'   => __( 'Get pro for this feature!', 'kindrex' ),
				'class'   => 'button-secondary',
				'onclick' => "window.open('https://www.designwicked.com/store/premium-kindrex', '_blank')",
			),
		)
	);

	/**
	 * Side Widget Title Section - END
	 */

	/**
	 * Center Widget Title Section - START
	 */
	$wp_customize->add_setting(
		'kindrex_centerh2_color',
		array(
			'default'           => '#2377ed',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize,
			'kindrex_centerh2_color',
			array(
				'label'       => __( 'Center Widget Title Color:', 'kindrex' ),
				'section'     => 'kindrex-coloring-section',
				'description' => esc_html__( 'Widget title color for center blocks.', 'kindrex' ),
				'settings'    => 'kindrex_centerh2_color',
			)
		)
	);

	/**
	 * Center Widget Title Section - END
	 */
}
add_action( 'customize_register', 'kindrex_color_changer' );

function kindrex_inline_style() {

	$text_color         = get_theme_mod( 'kindrex_links_color', '#2377ed' );
	$text_hover_color   = get_theme_mod( 'kindrex_links_hover_color', '#001489' );
	$megamenu_link      = get_theme_mod( 'kindrex_megamenu_link_color', '#a0a0a0' );
	$megamenu_linkhover = get_theme_mod( 'kindrex_megamenu_link_hover_color', '#ffffff' );
	$maintext           = get_theme_mod( 'kindrex_maintext_color', '#7f7f7f' );
	$sidebarh2          = get_theme_mod( 'kindrex_sidebarh2_color', '#4e4e4e' );
	$centerh2           = get_theme_mod( 'kindrex_centerh2_color', '#2377ed' );
	$bg_color           = get_theme_mod( 'kindrex_bg_color', '#cccccc' );

	$custom_css = "
	:root {
		--links: {$text_color};
		--links-hover: {$text_hover_color};
		--article-hover: {$text_color};
		--maintext: {$maintext};
		--titles: {$sidebarh2};
		--titles2: {$centerh2};
		--megamenu-a: {$megamenu_link};
		--megamenu-a-hover: {$megamenu_linkhover};
    	--primarybg: {$bg_color};
	}";

	wp_add_inline_style( 'kindrex-style', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'kindrex_inline_style' );

/**
 * Function for changing links and color hue. -- END
 */

function kindrex_remove_customizer_sections( $wp_customize ) {
	$wp_customize->remove_section( 'colors' );
}
add_action( 'customize_register', 'kindrex_remove_customizer_sections' );
