<?php
/**
 * Brimstone Theme Customizer
 *
 * @package WordPress
 * @subpackage Brimstone
 * @since 1.01
 * @author Chris Baldelomar <chris@webplantmedia.com>
 * @copyright Copyright (c) 2018, Chris Baldelomar
 * @link https://webplantmedia.com/product/brimstone-wordpress-theme/
 * @license http://www.gnu.org/licenses/gpl-2.0.html
 */

/**
 * Customizer support
 *
 * @since Brimstone 1.01
 *
 * @param object $wp_customize
 * @return void
 */
function brimstone_customize_register( $wp_customize ) {
	global $brimstone_default;

	require get_template_directory() . '/inc/class-customize-control.php';

	$wp_customize->get_setting( 'blogname' )->transport        = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname', array(
				'selector'        => '.site-title a',
				'render_callback' => 'brimstone_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription', array(
				'selector'        => '.site-description',
				'render_callback' => 'brimstone_customize_partial_blogdescription',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'custom_logo_2x', array(
				'selector'        => '.site-logo',
				'render_callback' => 'brimstone_customize_partial_custom_logo',
			)
		);
	}

	/**
	 * Logo
	 */
	$section_id = 'title_tagline';

	$setting_id = 'custom_logo_2x';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize, $setting_id, array(
				'label'         => esc_html__( 'Retina Logo', 'brimstone' ),
				'priority'      => 8, /* below the logo media selector. */
				'section'       => $section_id,
				'button_labels' => array(
					'select'       => esc_html__( 'Select Retina Logo', 'brimstone' ),
					'change'       => esc_html__( 'Change Retina Logo', 'brimstone' ),
					'placeholder'  => esc_html__( 'No retina logo selected', 'brimstone' ),
					'frame_title'  => esc_html__( 'Select Retina Logo', 'brimstone' ),
					'frame_button' => esc_html__( 'Choose Retina Logo', 'brimstone' ),
				),
				'description'   => esc_html__( 'Select image twice the size as your original logo image for crisp display on retina screens.', 'brimstone' ),
			)
		)
	);

	$setting_id = 'display_site_title';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Display Site Title', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'display_site_tagline';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Display Site Tagline', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'heading_padding_top';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'number',
			'label'   => esc_html__( 'Padding Top', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'heading_padding_bottom';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'number',
			'label'   => esc_html__( 'Padding Bottom', 'brimstone' ),
			'section' => $section_id,
		)
	);

	/**
	 * Custom colors.
	 */
	$section_id = 'colors';

	$setting_id = 'primary_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Primary Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	$setting_id = 'primary_hover_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Primary Hover Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	$setting_id = 'archive_background_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Archive Background Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	$setting_id = 'archive_title_light';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Display White Archive Title?', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'footer_background_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Footer Background Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	$setting_id = 'site_info_background_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Site Info Background Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	$setting_id = 'footer_text_light';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Display White Footer Text?', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'link_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Link Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	$setting_id = 'link_hover_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Link Hover Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	/**
	 * Theme options.
	 */
	$wp_customize->add_panel(
		'theme_options', array(
			'title'    => esc_html__( 'Theme Options', 'brimstone' ),
			'priority' => 330, // Before Additional CSS.
		)
	);

	/**
	 * Site
	 */
	$section_id = 'theme_options_site';
	$wp_customize->add_section(
		$section_id, array(
			'title' => esc_html__( 'Site', 'brimstone' ),
			'panel' => 'theme_options',
		)
	);

	$setting_id = 'show_menu_arrows';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Show Menu Arrows', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'show_menu_search';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Show Menu Search Button', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'default_button_style';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'        => 'select',
			'label'       => esc_html__( 'Default Button Style', 'brimstone' ),
			'description' => esc_html__( 'When you insert a link on its own line in the WP Editor, the theme turns it into a button. Choose the default style of your button to display in your post and pages.', 'brimstone' ),
			'section'     => $section_id,
			'choices'     => array(
				'default'  => esc_html__( 'Default Button', 'brimstone' ),
				'button-1' => esc_html__( 'Button Style 1', 'brimstone' ),
				'button-2' => esc_html__( 'Button Style 2', 'brimstone' ),
			),
		)
	);

	$setting_id = 'disable_body_font';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'            => 'checkbox',
			'label'           => esc_html__( 'Disable Body Font', 'brimstone' ),
			'description'     => esc_html__( 'If you are using a Google Font plugin, then you can disable the load of the body font.', 'brimstone' ),
			'section'         => $section_id,
			'active_callback' => 'brimstone_is_wpm_fonts_deactivated',
		)
	);

	$setting_id = 'disable_heading_font';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'            => 'checkbox',
			'label'           => esc_html__( 'Disable Heading Font', 'brimstone' ),
			'description'     => esc_html__( 'If you are using a Google Font plugin, then you can disable the load of the heading font.', 'brimstone' ),
			'section'         => $section_id,
			'active_callback' => 'brimstone_is_wpm_fonts_deactivated',
		)
	);

	$setting_id = 'disable_accent_font';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'            => 'checkbox',
			'label'           => esc_html__( 'Disable Accent Font', 'brimstone' ),
			'description'     => esc_html__( 'The accent font is a cursive font used in places such as your archive title. If you are using a Google Font plugin, then you can disable the load of this accent font.', 'brimstone' ),
			'section'         => $section_id,
			'active_callback' => 'brimstone_is_wpm_fonts_deactivated',
		)
	);

	$setting_id = 'page_image_header_height';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'section'     => $section_id,
			'type'        => 'range',
			'label'       => esc_html__( 'Page Image Header Height', 'brimstone' ),
			'description' => esc_html__( 'This changes the height of your featured image in your page header area.', 'brimstone' ),
			'section'     => $section_id,
			'input_attrs' => array(
				'min'   => 0,
				'max'   => 800,
				'step'  => 5,
				'style' => 'width:100%;',
			),
		)
	);

	$setting_id = 'post_image_header_height';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'section'     => $section_id,
			'type'        => 'range',
			'label'       => esc_html__( 'Post Image Header Height', 'brimstone' ),
			'description' => esc_html__( 'This changes the height of your featured image in your post header area.', 'brimstone' ),
			'section'     => $section_id,
			'input_attrs' => array(
				'min'   => 0,
				'max'   => 800,
				'step'  => 5,
				'style' => 'width:100%;',
			),
		)
	);

	/**
	 * Blog
	 */
	$section_id = 'theme_options_blog';
	$wp_customize->add_section(
		$section_id, array(
			'title' => esc_html__( 'Blog', 'brimstone' ),
			'panel' => 'theme_options',
		)
	);

	$setting_id = 'blog_display';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Blog Display', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				'blog1' => esc_html__( 'Lead Excerpt + Grid', 'brimstone' ),
				'blog4' => esc_html__( 'Grid', 'brimstone' ),
				'blog2' => esc_html__( 'Excerpt', 'brimstone' ),
				'blog3' => esc_html__( 'Content', 'brimstone' ),
			),
		)
	);

	$setting_id = 'archive_display';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Archive Display', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				'blog1' => esc_html__( 'Lead Excerpt + Grid', 'brimstone' ),
				'blog4' => esc_html__( 'Grid', 'brimstone' ),
				'blog2' => esc_html__( 'Excerpt', 'brimstone' ),
				'blog3' => esc_html__( 'Content', 'brimstone' ),
			),
		)
	);

	$setting_id = 'search_display';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Search Display', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				'blog1' => esc_html__( 'Lead Excerpt + Grid', 'brimstone' ),
				'blog4' => esc_html__( 'Grid', 'brimstone' ),
				'blog2' => esc_html__( 'Excerpt', 'brimstone' ),
				'blog3' => esc_html__( 'Content', 'brimstone' ),
			),
		)
	);

	$setting_id = 'thumb_excerpt_max_height';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'section'     => $section_id,
			'type'        => 'number',
			'label'       => esc_html__( 'Thumb Excerpt Max Height', 'brimstone' ),
			'description' => esc_html__( 'If you have long featured images in your excerpts, set a max-height on your image. Enter 0 for no max-height', 'brimstone' ),
			'section'     => $section_id,
			'input_attrs' => array(
				'min'  => 0,
				'step' => 1,
			),
		)
	);

	$setting_id = 'thumb_grid_max_height';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'section'     => $section_id,
			'type'        => 'number',
			'label'       => esc_html__( 'Thumb Grid Max Height', 'brimstone' ),
			'description' => esc_html__( 'If you have long featured images in your grid, set a max-height on your image. Enter 0 for no max-height', 'brimstone' ),
			'section'     => $section_id,
			'input_attrs' => array(
				'min'  => 0,
				'step' => 1,
			),
		)
	);

	$setting_id = 'blog_single_hide_post_navigation';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'        => 'checkbox',
			'label'       => esc_html__( 'Hide Post Navigation', 'brimstone' ),
			'description' => esc_html__( 'Hide the post navigation buttons at the bottom of each post.', 'brimstone' ),
			'section'     => $section_id,
		)
	);

	/**
	 * Jetpack
	 */
	$section_id = 'theme_options_jetpack';
	$wp_customize->add_section(
		$section_id, array(
			'title'           => esc_html__( 'Jetpack', 'brimstone' ),
			'panel'           => 'theme_options',
			'active_callback' => 'brimstone_is_jetpack_activated',
		)
	);

	$setting_id = 'jetpack_hide_share_count';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Share Button Count', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'jetpack_scroll_credit';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'wp_kses_post',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'text',
			'label'   => esc_html__( 'Infinite Scroll Credit Text', 'brimstone' ),
			'section' => $section_id,
		)
	);

	/**
	 * Shop
	 */
	$section_id = 'theme_options_shop';
	$wp_customize->add_section(
		$section_id, array(
			'title'           => esc_html__( 'Shop', 'brimstone' ),
			'panel'           => 'theme_options',
			'active_callback' => 'brimstone_is_woocommerce_activated',
		)
	);

	$setting_id = 'shop_columns';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Shop Columns', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				2 => esc_html__( '2', 'brimstone' ),
				3 => esc_html__( '3', 'brimstone' ),
				4 => esc_html__( '4', 'brimstone' ),
			),
		)
	);

	$setting_id = 'shop_archive_columns';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Shop Archive Columns', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				2 => esc_html__( '2', 'brimstone' ),
				3 => esc_html__( '3', 'brimstone' ),
				4 => esc_html__( '4', 'brimstone' ),
			),
		)
	);

	$setting_id = 'shop_related_products_columns';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Related Products Columns', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				2 => esc_html__( '2', 'brimstone' ),
				3 => esc_html__( '3', 'brimstone' ),
				4 => esc_html__( '4', 'brimstone' ),
			),
		)
	);

	$setting_id = 'shop_image_size';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_woocommerce_image_sizes',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Shop Image Size', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				'woocommerce_thumbnail' => esc_html__( 'Thumbnail', 'brimstone' ),
				'woocommerce_single'    => esc_html__( 'Main Image', 'brimstone' ),
			),
		)
	);

	$setting_id = 'shop_archive_image_size';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_woocommerce_image_sizes',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Shop Archive Image Size', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				'woocommerce_thumbnail' => esc_html__( 'Thumbnail', 'brimstone' ),
				'woocommerce_single'    => esc_html__( 'Main Image', 'brimstone' ),
			),
		)
	);

	$setting_id = 'shop_related_products_image_size';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_woocommerce_image_sizes',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'select',
			'label'   => esc_html__( 'Related Products Image Size', 'brimstone' ),
			'section' => $section_id,
			'choices' => array(
				'woocommerce_thumbnail' => esc_html__( 'Thumbnail', 'brimstone' ),
				'woocommerce_single'    => esc_html__( 'Main Image', 'brimstone' ),
			),
		)
	);

	$setting_id = 'shop_products_per_page';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'number',
			'label'   => esc_html__( 'Products Per Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_image_backdrop';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'        => 'checkbox',
			'label'       => esc_html__( 'Display Product Image Backdrop', 'brimstone' ),
			'description' => esc_html__( 'Add a light gray backdrop with a dropshadow for your product images. Visually helpful for images with light colored backgrounds.', 'brimstone' ),
			'section'     => $section_id,
		)
	);

	$setting_id = 'shop_hide_title';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Shop Title From Main Shop Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_hide_breadcrumbs';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Breadcrumbs From Shop Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_hide_stars';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Product Reviews From Shop Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_hide_result_count';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Result Count String From Shop Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_hide_catalog_ordering';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Ordering Dropdown From Shop Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_truncate_titles';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'        => 'checkbox',
			'label'       => esc_html__( 'Truncate Product Titles', 'brimstone' ),
			'description' => esc_html__( 'This will cause product titles to appear in one line.', 'brimstone' ),
			'section'     => $section_id,
		)
	);

	$setting_id = 'shop_product_hide_stars';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Product Reviews From Product Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_product_hide_meta';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Hide Product Meta From Product Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_disable_gallery_zoom';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Disable Gallery Zoom on Product Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_disable_gallery_lightbox';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Disable Gallery Lightbox on Product Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'shop_disable_gallery_slider';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Disable Gallery Slider on Product Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	/**
	 * Display Sidebar
	 */
	$section_id = 'theme_options_display_sidebar';
	$wp_customize->add_section(
		$section_id, array(
			'title'       => esc_html__( 'Display Sidebar', 'brimstone' ),
			'panel'       => 'theme_options',
			'description' => esc_html__( 'Check the pages where you want the sidebar to display.', 'brimstone' ),
		)
	);

	$setting_id = 'display_sidebar_blog';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Blog', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'display_sidebar_post';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Post', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'display_sidebar_archive';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Archive', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'display_sidebar_search';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Search', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'display_sidebar_shop';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
			'active_callback'   => 'brimstone_is_woocommerce_activated',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Shop', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'display_sidebar_shop_archive';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
			'active_callback'   => 'brimstone_is_woocommerce_activated',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Shop Archive', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'display_sidebar_attachment';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Attachment Page', 'brimstone' ),
			'section' => $section_id,
		)
	);

	/**
	 * Labels
	 */
	$section_id = 'theme_options_lables';
	$wp_customize->add_section(
		$section_id, array(
			'title' => esc_html__( 'Labels', 'brimstone' ),
			'panel' => 'theme_options',
		)
	);

	$setting_id = 'mobile_menu_label';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'text',
			'label'   => esc_html__( 'Mobile Menu Label', 'brimstone' ),
			'section' => $section_id,
		)
	);

	$setting_id = 'read_more_label';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'text',
			'label'   => esc_html__( 'Read More Label', 'brimstone' ),
			'section' => $section_id,
		)
	);

	/**
	 * 404 Error Page
	 */
	$section_id = 'theme_options_404';
	$wp_customize->add_section(
		$section_id, array(
			'title' => esc_html__( '404 Error Page', 'brimstone' ),
			'panel' => 'theme_options',
		)
	);

	$setting_id = '404_custom_page';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'label'          => esc_html__( 'Select 404 Page', 'brimstone' ),
			'description'    => esc_html__( 'Set the page\'s featured image for the background image to display.', 'brimstone' ),
			'type'           => 'dropdown-pages',
			'allow_addition' => true,
			'section'        => $section_id,
		)
	);

	$setting_id = '404_cover_opacity';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'        => 'range',
			'label'       => esc_html__( 'Page Cover Opacity', 'brimstone' ),
			'description' => esc_html__( 'Set opacity for 404 Page Cover\'s featured image.', 'brimstone' ),
			'section'     => $section_id,
			'input_attrs' => array(
				'min'   => 0,
				'max'   => 100,
				'step'  => 1,
				'style' => 'width:100%;',
			),
		)
	);

	$setting_id = '404_cover_color';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'postMessage',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize, $setting_id, array(
				'label'   => esc_html__( 'Page Cover Color', 'brimstone' ),
				'section' => $section_id,
			)
		)
	);

	$setting_id = '404_text_white';
	$wp_customize->add_setting(
		$setting_id, array(
			'default'           => $brimstone_default[ $setting_id ],
			'transport'         => 'refresh',
			'sanitize_callback' => 'brimstone_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		$setting_id, array(
			'type'    => 'checkbox',
			'label'   => esc_html__( 'Display White Text', 'brimstone' ),
			'section' => $section_id,
		)
	);

	if ( brimstone_is_wpm_fonts_deactivated() ) {
		/**
		 * Fonts
		 */
		$section_id = 'wpm_fonts';
		$wp_customize->add_section(
			$section_id, array(
				'title'    => esc_html__( 'Fonts', 'brimstone' ),
				'panel'    => 'theme_options',
				'priority' => 331, // Before Additional CSS.
			)
		);

		$setting_id = 'wpm_fonts_notice';
		$wp_customize->add_setting(
			$setting_id, array(
				'default'           => '',
				'transport'         => 'refresh',
				'sanitize_callback' => 'int',
			)
		);

		$wp_customize->add_control(
			new Brimstone_Notice_Control(
				$wp_customize,
				$setting_id,
				array(
					'label'       => esc_html__( 'Font Customization', 'brimstone' ),
					'description' => sprintf(
						/* Translators: this string is a link to a self hosted WordPress plugin. */
						esc_html__( 'To easily change the font styles for your theme, please download our %s plugin.', 'brimstone' ),
						'<a target="_blank" href="https://webplantmedia.com/product/designer-fonts-wordpress-plugin/"><span style="text-decoration:none;" class="dashicons dashicons-external"></span>' . esc_html__( 'Designer Fonts', 'brimstone' ) . '</a>'
					),
					'section'     => $section_id,
					'settings'    => $setting_id,
				)
			)
		);
	}
}
add_action( 'customize_register', 'brimstone_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @since Brimstone 1.01
 *
 * @return void
 */
function brimstone_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @since Brimstone 1.01
 *
 * @return void
 */
function brimstone_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Render the site logo for the selective refresh partial.
 *
 * @since Brimstone 1.01
 *
 * @return void
 */
function brimstone_customize_partial_custom_logo() {
	the_custom_logo();
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 *
 * @since Brimstone 1.01
 *
 * @return void
 */
function brimstone_customize_preview_js() {
	wp_enqueue_script( 'brimstone-customizer', get_template_directory_uri() . '/js/admin/customizer.js', array( 'customize-preview' ), BRIMSTONE_VERSION, true );
	wp_enqueue_script( 'brimstone-admin-notifier', get_template_directory_uri() . '/js/admin/admin-notifier.js', array( 'customize-preview' ), BRIMSTONE_VERSION, true );
	wp_enqueue_style( 'brimstone-customizer-style', get_parent_theme_file_uri() . '/css/admin/customizer.css', array(), BRIMSTONE_VERSION );
}
add_action( 'customize_preview_init', 'brimstone_customize_preview_js' );

/**
 * Sanitize the page layout options.
 *
 * @since Brimstone 1.01
 *
 * @param mixed $input
 * @return int
 */
function brimstone_sanitize_checkbox( $input ) {
	if ( 1 === intval( $input ) ) {
		return 1;
	}

	return 0;
}

/**
 * Sanitize the WooCommerce image sizes.
 *
 * @since Brimstone 1.01
 *
 * @param string $input
 * @return string
 */
function brimstone_sanitize_woocommerce_image_sizes( $input ) {
	if ( 'woocommerce_single' === $input ) {
		return 'woocommerce_single';
	}

	return 'woocommerce_thumbnail';
}
