<?php
/**
 * Register Theme Font section, settings and controls for Theme Customizer
 *
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
// Add Theme Fonts section to Customizer
add_action( 'customize_register', 'pmthemes_customize_register_font_settings' );
function pmthemes_customize_register_font_settings( $wp_customize ) {
    // Get Default Fonts from settings
    $theme_def = pmthemes_default_options();
    // Google Font Setting Header
	$wp_customize->add_setting( 'pmthemes_theme_options[default_fonts]', array(
        'default'           => '',
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Header_Control(
        $wp_customize, 'pmthemes_control_default_fonts', array(
            'label' => __( 'Enable Google Fonts?', 'pmthemes' ),
            'section' => 'pmthemes_section_fonts',
            'settings' => 'pmthemes_theme_options[default_fonts]',
            'priority' => 1,
            )
        )
    );
    // Activate Google Font setting
	$wp_customize->add_setting( 'pmthemes_theme_options[activate_google_fonts]', array(
        'default'           => $theme_def['activate_google_fonts'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_activate_google_fonts', array(
        'label'    => __( 'Check this to activate Google Fonts. If uncheck, only Default Browser Safe Fonts is active.', 'pmthemes' ),
        'section'  => 'pmthemes_section_fonts',
        'settings' => 'pmthemes_theme_options[activate_google_fonts]',
        'type'     => 'checkbox',
		'priority' => 2,
		)
	);
    // Choose Available Fonts
    $wp_customize->add_setting( 'pmthemes_theme_options[available_fonts]', array(
            'default'           => $theme_def['available_fonts'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_available_fonts'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Font_List_Control(
            $wp_customize, 'pmthemes_control_available_fonts', array(
            'label'      => __( 'Choose available Fonts', 'pmthemes' ),
            'section'    => 'pmthemes_section_fonts',
            'settings'   => 'pmthemes_theme_options[available_fonts]',
            'choices' => array(
                'default' => __( 'Default Browser Fonts (12)', 'pmthemes' ),
                'favorites' => __( 'Most Popular Fonts (35)', 'pmthemes' ),
                'popular' => __( 'Most Popular Google Fonts (100)', 'pmthemes' ),
                'all' => __( 'All Google Fonts (650)', 'pmthemes' )
            ),
            'priority' => 3,
        ) )
    );
    // Default Text Font
	$wp_customize->add_setting( 'pmthemes_theme_options[text_font]', array(
        'default'           => $theme_def['text_font'],
		'type'           	=> 'option',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'esc_attr'
		)
	);
	$wp_customize->add_control( new Pmthemes_Customize_Font_Control(
		$wp_customize, 'text_font', array(
			'label'      => __( 'Default Text Font', 'pmthemes' ),
			'section'    => 'pmthemes_section_fonts',
			'settings'   => 'pmthemes_theme_options[text_font]',
			'priority' => 4,
		) ) 
	);
    // Default Site Title Font
    $wp_customize->add_setting( 'pmthemes_theme_options[site_title_font]', array(
            'default'           => $theme_def['site_title_font'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Font_Control(
            $wp_customize, 'site_title_font', array(
            'label'      => __( 'Site Title Font', 'pmthemes' ),
            'section'    => 'pmthemes_section_fonts',
            'settings'   => 'pmthemes_theme_options[site_title_font]',
            'priority' => 5,
        ) )
    );
    // Post/Page Title Font
	$wp_customize->add_setting( 'pmthemes_theme_options[title_font]', array(
        'default'           => $theme_def['title_font'],
		'type'           	=> 'option',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'esc_attr'
		)
	);
	$wp_customize->add_control( new Pmthemes_Customize_Font_Control(
		$wp_customize, 'title_font', array(
			'label'      => __( 'Post/Page Title Font', 'pmthemes' ),
			'section'    => 'pmthemes_section_fonts',
			'settings'   => 'pmthemes_theme_options[title_font]',
			'priority' => 6,
		) ) 
	);
    // Navigation Font
	$wp_customize->add_setting( 'pmthemes_theme_options[navi_font]', array(
        'default'           => $theme_def['navi_font'],
		'type'           	=> 'option',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'esc_attr'
		)
	);
	$wp_customize->add_control( new Pmthemes_Customize_Font_Control(
		$wp_customize, 'navi_font', array(
			'label'      => __( 'Navigation Font', 'pmthemes' ),
			'section'    => 'pmthemes_section_fonts',
			'settings'   => 'pmthemes_theme_options[navi_font]',
			'priority' => 7,
		) ) 
	);
    // Widget Title Font
	$wp_customize->add_setting( 'pmthemes_theme_options[widget_title_font]', array(
        'default'           => $theme_def['widget_title_font'],
		'type'           	=> 'option',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'esc_attr'
		)
	);
	$wp_customize->add_control( new Pmthemes_Customize_Font_Control(
		$wp_customize, 'widget_title_font', array(
			'label'      => __( 'Widget Title Font', 'pmthemes' ),
			'section'    => 'pmthemes_section_fonts',
			'settings'   => 'pmthemes_theme_options[widget_title_font]',
			'priority' => 8,
		) ) 
	);

}