<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
// Load Customizer Helper Functions
require get_template_directory() . '/inc/customizer/functions/custom-controls.php';
require get_template_directory() . '/inc/customizer/functions/active-callbacks.php';
require get_template_directory() . '/inc/customizer/functions/sanitize-functions.php';
require get_template_directory() . '/inc/customizer/functions/custom-font-lists.php';
// Load Customizer Settings
require get_template_directory() . '/inc/customizer/sections/customizer-colors.php';
require get_template_directory() . '/inc/customizer/sections/customizer-fonts.php';
require get_template_directory() . '/inc/customizer/sections/customizer-general.php';
require get_template_directory() . '/inc/customizer/sections/customizer-header.php';
require get_template_directory() . '/inc/customizer/sections/customizer-title.php';
require get_template_directory() . '/inc/customizer/sections/customizer-navi.php';
require get_template_directory() . '/inc/customizer/sections/customizer-sidebar.php';
require get_template_directory() . '/inc/customizer/sections/customizer-post.php';
require get_template_directory() . '/inc/customizer/sections/customizer-archive.php';
require get_template_directory() . '/inc/customizer/sections/customizer-slider.php';
require get_template_directory() . '/inc/customizer/sections/customizer-footer.php';
// Add Theme Options section to Customizer
add_action( 'customize_register', 'pmthemes_customize_register_options' );
function pmthemes_customize_register_options( $wp_customize ) {
    // Register custom controls
    if ( method_exists( $wp_customize,'register_control_type' ) ) {
        $wp_customize->register_control_type( 'Pmthemes_Control_Toggle' );
        $wp_customize->register_control_type( 'Pmthemes_Spacing_Control' );
    }
	// Add Theme Options Panel
	$wp_customize->add_panel( 'pmthemes_options_panel', array(
		'priority'       => 1,
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __( 'Theme Settings', 'pmthemes' ),
		'description'    => '',
	) );
	// Add Color Options Panel
	$wp_customize->add_panel( 'pmthemes_colors_panel', array(
		'priority'       => 102,
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __( 'Colors', 'pmthemes' ),
		'description'    => '',
	) );
    // Add Section for Theme Fonts
    $wp_customize->add_section( 'pmthemes_section_fonts', array(
            'priority' => 101,
            'capability'     => 'edit_theme_options',
            'theme_supports' => '',
            'title'    => __( 'Fonts', 'pmthemes' ),
            'description'    => '',
        )
    );
	// Add postMessage support for site title and description.
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	// Organize Customizer Area
	$wp_customize->get_control( 'background_color'  )->section   = 'background_image';
	$wp_customize->get_section( 'background_image'  )->title     = 'Site Background';
	$wp_customize->get_section('static_front_page')->title = __( 'Front Page Settings', 'pmthemes' );
	$wp_customize->get_section('static_front_page')->panel = 'pmthemes_options_panel';
	$wp_customize->get_section('static_front_page')->priority = 5;
}
// Embed JS file to make Theme Customizer preview reload changes asynchronously.
add_action( 'customize_preview_init', 'pmthemes_customize_preview_js' );
function pmthemes_customize_preview_js() {
	wp_enqueue_script( 'pmthemes-customizer-js', PMTHEMES_URI . '/inc/customizer/assets/js/customizer-preview.js', array( 'customize-preview' ), '20150423', true );
    // Localize our script
    $translation_array = array( 'themeUrl' => get_template_directory_uri());
    wp_localize_script( 'pmthemes-customizer-js', 'pmth_js_uri', $translation_array );
}
// Embed CSS styles for Theme Customizer
add_action( 'customize_controls_print_styles', 'pmthemes_customize_preview_css' );
function pmthemes_customize_preview_css() {
	wp_enqueue_style( 'pmthemes-customizer-css', PMTHEMES_URI . '/inc/customizer/assets/css/customizer.css', array(), '20150423' );
}