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

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */

function fatal_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'fatal_customize_partial_blogname',
			)
		);

		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'fatal_customize_partial_blogdescription',
			)
		);	

	 // adding copyright section to the fatal customizer 

    	$wp_customize-> add_section('fatal_copyright_sec', array(
		'title'                    => __('Copyright','fatal'),
		'description'              => __('Please, type here your copyright','fatal')
	 ));
	
	 $wp_customize-> add_setting('fatal_copyright_set', array(
		'type'                     => 'theme_mod',
		'sanitize_callback'        => 'esc_html'
	 ));


    	$wp_customize-> add_control( 'fatal_ctrl_copyright', array(
		'label'                   => __('Copyright Information','fatal'),
		'description'             => __('Please, type your copyright here.','fatal'),
		'section'                 => 'fatal_copyright_sec',
		'settings'                => 'fatal_copyright_set',
		'type'                    => 'text'
    	));


	// adding footer column choice 

	$wp_customize-> add_section('fatal_foot_col_choice_sc', array(
		'title'                    => __('Footer Column Choice','fatal'),
		'description' => __('Please, choose your Footer Column Layout','fatal')
	 ));
	

	 $wp_customize-> add_setting('fatal_foot_col_choice_st', array(
		'type'                     => 'theme_mod',
		'sanitize_callback'        => 'fatal_sanitize_footer_widget'
	 ));


	 $wp_customize-> add_control( 'fatal_foot_col_choice_ctrl', array(
		'label'                   => __('Footer Column Choice','fatal'),
		'description'             => __('Please, choose your Footer Column Layout','fatal'),
		'section'                 => 'fatal_foot_col_choice_sc',
		'settings'                => 'fatal_foot_col_choice_st',
		'type'                    => 'select',
		'choices'                 => array(
		'two'                     => __( 'Two Column','fatal' ),
		'three'                   => __( 'Three Column','fatal' ),
		'four'                    => __( 'Four Column','fatal' ),
		  ),
	 ));

	 function fatal_sanitize_footer_widget($input, $setting) {

		$choices = array('two','three','four');
		if (in_array($input, $choices)) {
			return $input;
		} else {
			return "three";
		}
	 }


	// adding sidebar location setting to customizer
	 $wp_customize-> add_section('fatal_sidebar_sec', array(
		'title'                    => __('Sidebar Location','fatal'),
		'description'             => __('Please, choose your sidebar location','fatal'),

	 ));
	
	 $wp_customize-> add_setting('fatal_sidebar_set', array(
		'type'                     => 'theme_mod',
		'sanitize_callback'        => 'fatal_sanitize_sidebar'
	 ));

	 $wp_customize-> add_control( 'fatal_ctrl_sidebar', array(
		'label'                   => __('Sidebar Location','fatal'),
		'description'             => __('Please, choose your sidebar location','fatal'),
		'section'                 => 'fatal_sidebar_sec',
		'settings'                => 'fatal_sidebar_set',
		'type'                    => 'select',
		'choices'                 => array(
		'left'                    => __( 'Left Side' ,'fatal'),
		'right'                   => __( 'Right Side','fatal' ),
		'none'                    => __( 'No Sidebar','fatal' ),
		  ),
	 ));

	 function fatal_sanitize_sidebar($input, $setting) {

		$choices = array('right','left','none');
		if (in_array($input, $choices)) {
			return $input;
		} else {
			return "right";
		}
	 }

   }
}
add_action( 'customize_register', 'fatal_customize_register' );




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

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

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function fatal_customize_preview_js() {
	wp_enqueue_script( 'fatal-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), fatal, true );
}
add_action( 'customize_preview_init', 'fatal_customize_preview_js' );
