<?php
/**
 * salientthemes themes Theme Customizer
 *
 * @package salient themes
 * @subpackage moment
 * @since Moment 1.0.0
 */
add_filter('salientthemes_customizer_framework_url', 'moment_customizer_framework_url');

if( ! function_exists( 'moment_customizer_framework_url' ) ):

    function moment_customizer_framework_url(){
        return trailingslashit( get_template_directory_uri() ) . 'inc/frameworks/salientthemes-customizer/';
    }

endif;

add_filter('salientthemes_customizer_framework_path', 'moment_customizer_framework_path');

if( ! function_exists( 'moment_customizer_framework_path' ) ):
    function moment_customizer_framework_path(){
        return trailingslashit( get_template_directory() ) . 'inc/frameworks/salientthemes-customizer/';
    }
endif;

/*define constant for coder-customizer-constant*/
if(!defined('SALIENTTHEMES_CUSTOMIZER_NAME')){
    define('SALIENTTHEMES_CUSTOMIZER_NAME','moment-options');
}


/**
 * reset options
 * @param  array $reset_options
 * @return void
 *
 * @since Moment 1.0
 */
if ( ! function_exists( 'moment_reset_options' ) ) :
    function moment_reset_options( $reset_options ) {
        set_theme_mod( SALIENTTHEMES_CUSTOMIZER_NAME, $reset_options );
    }
endif;
/**
 * Customizer framework added.
 */
require get_template_directory().'/inc/frameworks/salientthemes-customizer/salientthemes-customizer.php';

global $moment_panels;
global $moment_sections;
global $moment_settings_controls;
global $moment_repeated_settings_controls;
global $moment_customizer_defaults;

/******************************************
Modify Site Identity sections
 *******************************************/
require get_template_directory().'/inc/customizer/site-identity/site-identity.php';

/******************************************
Modify Site Color sections
 *******************************************/
require get_template_directory().'/inc/customizer/colors/general.php';

/******************************************
Added font setting options
 *******************************************/
require get_template_directory().'/inc/customizer/font-setting/font-family.php';

/******************************************
Featured Slider options
 *******************************************/
require get_template_directory().'/inc/customizer/featured-slider/slider-panel.php';


/******************************************
About Section *******************************************/
require get_template_directory().'/inc/customizer/home-about/panel.php';


/******************************************
Popular Popular options
 *******************************************/
require get_template_directory().'/inc/customizer/home-popular/home-popular-panel.php';

/******************************************
Home Showcase options 
 *******************************************/
require get_template_directory().'/inc/customizer/home-showcase/home-showcase-panel.php';

/******************************************
Theme options panel
 *******************************************/
require get_template_directory().'/inc/customizer/theme-options/option-panel.php';

/*Resetting all Values*/
/**
 * Reset color settings to default
 * @param  $input
 *
 * @since Moment 1.0
 */
$moment_customizer_defaults['moment-customizer-reset'] = '';
if ( ! function_exists( 'moment_customizer_reset' ) ) :
    function moment_customizer_reset( $input ) {
        if ( $input == 1 ) {
            global $moment_customizer_defaults;

            $moment_customizer_defaults['moment-customizer-reset'] = '';
            /*resetting fields*/
            moment_reset_options( $moment_customizer_defaults );
        }
        else {
            return '';
        }
    }
endif;
$moment_sections['moment-customizer-reset'] =
    array(
        'priority'       => 999,
        'title'          => __( 'Reset All Options', 'moment' )
    );
$moment_settings_controls['moment-customizer-reset'] =
    array(
        'setting' =>     array(
            'default'              => $moment_customizer_defaults['moment-customizer-reset'],
            'sanitize_callback'    => 'moment_customizer_reset',
            'transport'            => 'postmessage'
        ),
        'control' => array(
            'label'                 =>  __( 'Reset All Options', 'moment' ),
            'description'           =>  __( 'Caution: Reset all options settings to default. Refresh the page after save to view the effects. ', 'moment' ),
            'section'               => 'moment-customizer-reset',
            'type'                  => 'checkbox',
            'priority'              => 10
        )
    );

/******************************************
Removing section setting control
 *******************************************/

$moment_remove_sections =
    array(
        'header_image' 
    );


$moment_customizer_args = array(
    'panels'            => $moment_panels, /*always use key panels */
    'sections'          => $moment_sections,/*always use key sections*/
    'settings_controls' => $moment_settings_controls,/*always use key settings_controls*/
    'repeated_settings_controls' => $moment_repeated_settings_controls,/*always use key sections*/
    'remove_sections'   => $moment_remove_sections,/*always use key remove_sections*/
);

/*registering panel section setting and control start*/
function moment_add_panels_sections_settings() {
    global $moment_customizer_args;
    return $moment_customizer_args;
}
add_filter( 'salientthemes_customizer_panels_sections_settings', 'moment_add_panels_sections_settings' );
/*registering panel section setting and control end*/

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function moment_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';
}
add_action( 'customize_register', 'moment_customize_register' );
/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function moment_customize_preview_js() {
    wp_enqueue_script( 'moment-customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20160105', true );
}
add_action( 'customize_preview_init', 'moment_customize_preview_js' );



/**
 * get all saved options
 * @param  null
 * @return array saved options
 *
 * @since Moment 1.0
 */
if ( ! function_exists( 'moment_get_all_options' ) ) :
    function moment_get_all_options( $merge_default = 0 ) {
        $moment_customizer_saved_values = salientthemes_customizer_get_all_values( );
        if( 1 == $merge_default ){
            global $moment_customizer_defaults;
            if(is_array( $moment_customizer_saved_values )){
                $moment_customizer_saved_values = array_merge($moment_customizer_defaults, $moment_customizer_saved_values );
            }
            else{
                $moment_customizer_saved_values = $moment_customizer_defaults;
            }
        }
        return $moment_customizer_saved_values;
    }
endif;