<?php
/**
 * Theme Customizer
 *
 * @package Signify
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function signify_color_scheme_register( $wp_customize ) {
	//Color Scheme
	$color_scheme = signify_get_color_scheme();

	signify_register_option( $wp_customize, array(
			'name'              => 'theme_scheme',
			'default'           => 'default',
			'sanitize_callback' => 'signify_sanitize_select',
			'transport'         => 'postMessage',
			'label'             => esc_html__( 'Theme Scheme', 'signify-pro' ),
			'section'           => 'colors',
			'type'              => 'select',
			'choices'           => array(
				'default'     	=> esc_html__( 'Default', 'signify-pro' ),
				'wedding'     	=> esc_html__( 'Wedding', 'signify-pro' ),
				'education'   	=> esc_html__( 'Education', 'signify-pro' ),
				'corporate'   	=> esc_html__( 'Corporate', 'signify-pro' ),
				'photography' 	=> esc_html__( 'Photography', 'signify-pro' ),
				'ecommerce'   	=> esc_html__( 'eCommerce', 'signify-pro' ),
				'tune' 			=> esc_html__( 'Tune', 'signify-pro' ),
				'music-dark'  	=> esc_html__( 'Music Dark', 'signify-pro' ),
			),
			'priority'          => 1,
			'description'       => esc_html__( 'Caution: Changing this option will change design settings like alignments, headers and menus', 'signify-pro' ),
		)
	);

	// Add color scheme setting and control.
	signify_register_option( $wp_customize, array(
			'name'              => 'color_scheme',
			'default'           => 'default',
			'sanitize_callback' => 'signify_sanitize_select',
			'transport'         => 'refresh',
			'label'             => esc_html__( 'Base Color Scheme', 'signify-pro' ),
			'section'           => 'colors',
			'type'              => 'select',
			'choices'           => signify_get_color_scheme_choices(),
			'priority'          => 1,
		)
	);

	$color_options = signify_color_options();

	foreach ( $color_options as $key => $value ) {
		signify_register_option( $wp_customize, array(
				'name'              => $key,
				'default'           => $value['default'],
				'sanitize_callback' => 'sanitize_hex_color',
				'transport'         => 'postMessage',
				'custom_control'    => 'WP_Customize_Color_Control',
				'label'             => $value['label'],
				'section'           => 'colors',
			)
		);
	}

	$wp_customize->get_control( 'header_textcolor' )->priority= 2;
	$wp_customize->get_control( 'background_color' )->priority= 4;
	$wp_customize->get_control( 'absolute_header_menu_text_color' )->active_callback = 'signify_is_absolute_color_scheme_active';
	$wp_customize->get_control( 'absolute_header_text_color' )->active_callback = 'signify_is_absolute_color_scheme_active';
}
add_action( 'customize_register', 'signify_color_scheme_register' );

if ( ! function_exists( 'signify_is_absolute_color_scheme_active' ) ) :
	/**
	* Return true if page content is active
	*
	* @since 1.0.0
	*/
	function signify_is_absolute_color_scheme_active( $control ) {
		$color_scheme = $control->manager->get_setting( 'color_scheme' )->value();

		return ( 'wedding' === $color_scheme || 'photography' === $color_scheme || 'corporate' === $color_scheme || 'music' === $color_scheme );
	}
endif;
