<?php
/**
 * Prime Magazine Theme Customizer.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package prime_magazine
 */

if( ! function_exists( 'prime_magazine_customize_register' ) ):  
/**
 * Add postMessage support for site title and description for the Theme Customizer.F
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function prime_magazine_customize_register( $wp_customize ) {
require get_parent_theme_file_path('/inc/controls/changeable-icon.php');

require get_parent_theme_file_path('/inc/controls/sortable-control.php');

//Register the sortable control type.
$wp_customize->register_control_type( 'Prime_Magazine_Control_Sortable' ); 

    if ( version_compare( get_bloginfo('version'),'4.9', '>=') ) {
        $wp_customize->get_section( 'static_front_page' )->title = __( 'Static Front Page', 'prime-magazine' );
    }
	
    /* Option list of all post */	
    $prime_magazine_options_posts = array();
    $prime_magazine_options_posts_obj = get_posts('posts_per_page=-1');
    $prime_magazine_options_posts[''] = esc_html__( 'Choose Post', 'prime-magazine' );
    foreach ( $prime_magazine_options_posts_obj as $posts ) {
    	$prime_magazine_options_posts[$posts->ID] = $posts->post_title;
    }
    
    /* Option list of all categories */
    $prime_magazine_args = array(
	   'type'                     => 'post',
	   'orderby'                  => 'name',
	   'order'                    => 'ASC',
	   'hide_empty'               => 1,
	   'hierarchical'             => 1,
	   'taxonomy'                 => 'category'
    ); 
    $prime_magazine_option_categories = array();
    $prime_magazine_category_lists = get_categories( $prime_magazine_args );
    $prime_magazine_option_categories[''] = esc_html__( 'Choose Category', 'prime-magazine' );
    foreach( $prime_magazine_category_lists as $prime_magazine_category ){
        $prime_magazine_option_categories[$prime_magazine_category->term_id] = $prime_magazine_category->name;
    }
    
    /** Default Settings */    
    $wp_customize->add_panel( 
        'wp_default_panel',
         array(
            'priority' => 10,
            'capability' => 'edit_theme_options',
            'theme_supports' => '',
            'title' => esc_html__( 'Default Settings', 'prime-magazine' ),
            'description' => esc_html__( 'Default section provided by wordpress customizer.', 'prime-magazine' ),
        ) 
    );
    
    $wp_customize->get_section( 'title_tagline' )->panel                  = 'wp_default_panel';
    $wp_customize->get_section( 'colors' )->panel                         = 'wp_default_panel';
    $wp_customize->get_section( 'header_image' )->panel                   = 'wp_default_panel';
    $wp_customize->get_section( 'background_image' )->panel               = 'wp_default_panel';
    $wp_customize->get_section( 'static_front_page' )->panel              = 'wp_default_panel';
    
    $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
    
    /** Default Settings Ends */

    /** Site Title control */
    $wp_customize->add_setting( 
        'header_site_title', 
        array(
            'default'           => false,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'header_site_title',
        array(
            'label'       => __( 'Show / Hide Site Title', 'prime-magazine' ),
            'section'     => 'title_tagline',
            'type'        => 'checkbox',
        )
    );

    /** Tagline control */
    $wp_customize->add_setting( 
        'header_tagline', 
        array(
            'default'           => false,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'header_tagline',
        array(
            'label'       => __( 'Show / Hide Tagline', 'prime-magazine' ),
            'section'     => 'title_tagline',
            'type'        => 'checkbox',
        )
    );

    $wp_customize->add_setting('logo_width', array(
        'sanitize_callback' => 'absint', 
    ));

    // Add a control for logo width
    $wp_customize->add_control('logo_width', array(
        'label' => __('Logo Width', 'prime-magazine'),
        'section' => 'title_tagline',
        'type' => 'number',
        'input_attrs' => array(
            'min' => '50', 
            'max' => '500', 
            'step' => '5', 
    ),
        'default' => '100', 
    ));

    $wp_customize->add_setting( 'prime_magazine_site_title_size', array(
        'default'           => 30, // Default font size in pixels
        'sanitize_callback' => 'absint', // Sanitize the input as a positive integer
    ) );

    // Add control for site title size
    $wp_customize->add_control( 'prime_magazine_site_title_size', array(
        'type'        => 'number',
        'section'     => 'title_tagline', // You can change this section to your preferred section
        'label'       => __( 'Site Title Font Size (px)', 'prime-magazine' ),
        'input_attrs' => array(
            'min'  => 10,
            'max'  => 100,
            'step' => 1,
        ),
    ) );

    //Global Color
    $wp_customize->add_section(
        'prime_magazine_global_color',
        array(
            'title' => esc_html__( 'Global Color Settings', 'prime-magazine' ),
            'priority' => 20,
            'capability' => 'edit_theme_options',
            'panel' => 'prime_magazine_home_general_settings',
        )
    );

    $wp_customize->add_setting('prime_magazine_primary_color', array(
        'default'           => '#007bff',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'prime_magazine_primary_color', array(
        'label'    => __('Theme Primary Color', 'prime-magazine'),
        'section'  => 'prime_magazine_global_color',
        'settings' => 'prime_magazine_primary_color',
    ))); 

    /** Post & Pages Settings */
    $wp_customize->add_panel( 
        'prime_magazine_post_settings',
         array(
            'priority' => 9,
            'capability' => 'edit_theme_options',
            'title' => esc_html__( 'Post & Pages Settings', 'prime-magazine' ),
            'description' => esc_html__( 'Customize Post & Pages Settings', 'prime-magazine' ),
        ) 
    );

        /** Post Layouts */
    
    $wp_customize->add_section(
        'prime_magazine_post_layout_section',
        array(
            'title' => esc_html__( 'Post Layout Settings', 'prime-magazine' ),
            'priority' => 20,
            'capability' => 'edit_theme_options',
            'panel' => 'prime_magazine_post_settings',
        )
    );

    $wp_customize->add_setting('prime_magazine_post_layout_setting', array(
        'default'           => 'right-sidebar',
        'sanitize_callback' => 'prime_magazine_sanitize_post_layout',
    ));

    $wp_customize->add_control('prime_magazine_post_layout_setting', array(
        'label'    => __('Post Column Settings', 'prime-magazine'),
        'section'  => 'prime_magazine_post_layout_section',
        'settings' => 'prime_magazine_post_layout_setting',
        'type'     => 'select',
        'choices'  => array(        
            'right-sidebar'   => __('Right Sidebar', 'prime-magazine'),
            'left-sidebar'   => __('Left Sidebar', 'prime-magazine'),
            'one-column'   => __('One Column', 'prime-magazine'),
            'three-column'   => __('Three Columns', 'prime-magazine'),
            'four-column'   => __('Four Columns', 'prime-magazine'),
            'grid-layout'   => __('Grid Layout', 'prime-magazine')
        ),
    ));

    $wp_customize->add_setting('prime_magazine_archive_pagination_alignment',array(
        'default' => 'left-align',
        'sanitize_callback' => 'prime_magazine_sanitize_pagination_alignment'
    ));
    $wp_customize->add_control('prime_magazine_archive_pagination_alignment',array(
        'type' => 'select',
        'label' => __('Pagination Alignment','prime-magazine'),
        'section' => 'prime_magazine_post_layout_section',
        'choices' => array(
            'right-align' => __('Right Alignment','prime-magazine'),
            'center-align' => __('Center Alignment','prime-magazine'),
            'left-align' => __('Left Alignment','prime-magazine'),
        ),
    ) );

     /** Post Layouts Ends */


    /** Post Settings */
    $wp_customize->add_section(
        'prime_magazine_post_settings',
        array(
            'title' => esc_html__( 'Post Settings', 'prime-magazine' ),
            'priority' => 20,
            'capability' => 'edit_theme_options',
            'panel' => 'prime_magazine_post_settings',
        )
    );

    $wp_customize->add_setting( 
        'prime_magazine_post_excerpt_length', 
        array(
            'default'           => '50',
            'sanitize_callback' => 'prime_magazine_sanitize_number_range',
    ) );
    $wp_customize->add_control( 
        'prime_magazine_post_excerpt_length', 
        array(
            'label'       => esc_html__( 'Excerpt Length', 'prime-magazine' ),
            'section'     => 'prime_magazine_post_settings',
            'type'        => 'number',
            'input_attrs' => array( 'min' => 1, 'max' => 200, 'style' => 'width: 100%;' ),
    ) );

    /** Post Heading control */
    $wp_customize->add_setting( 
        'prime_magazine_post_heading_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_post_heading_setting',
        array(
            'label'       => __( 'Show / Hide Post Heading', 'prime-magazine' ),
            'section'     => 'prime_magazine_post_settings',
            'type'        => 'checkbox',
        )
    );

    /** Post Meta control */
    $wp_customize->add_setting( 
        'prime_magazine_post_meta_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_post_meta_setting',
        array(
            'label'       => __( 'Show / Hide Post Meta', 'prime-magazine' ),
            'section'     => 'prime_magazine_post_settings',
            'type'        => 'checkbox',
        )
    );

    /** Post Image control */
    $wp_customize->add_setting( 
        'prime_magazine_post_image_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_post_image_setting',
        array(
            'label'       => __( 'Show / Hide Post Image', 'prime-magazine' ),
            'section'     => 'prime_magazine_post_settings',
            'type'        => 'checkbox',
        )
    );

        $wp_customize->add_setting('prime_magazine_single_post_align',array(
        'default' => 'left-align',
        'sanitize_callback' => 'prime_magazine_sanitize_post_content_align'
    ));
    $wp_customize->add_control('prime_magazine_single_post_align',array(
        'type' => 'select',
        'label' => __('Post Content Alignment','prime-magazine'),
        'section' => 'prime_magazine_post_settings',
        'choices' => array(
            'left-align' => __('Left Alignment','prime-magazine'),
            'right-align' => __('Right Alignment','prime-magazine'),
            'center-align' => __('Center Alignment','prime-magazine'),
        ),
    ) );

    $wp_customize->add_setting('prime_magazine_blog_meta_order', array(
        'default' => array('heading', 'author', 'featured-image', 'content','button'),
        'sanitize_callback' => 'prime_magazine_sanitize_sortable',
    ));
    $wp_customize->add_control(new Prime_Magazine_Control_Sortable($wp_customize, 'prime_magazine_blog_meta_order', array(
        'label' => esc_html__('Post Meta Ordering', 'prime-magazine'),
        'description' => __('Drag & drop post items to rearrange the ordering ( this control will not function by post format )', 'prime-magazine') ,
        'section' => 'prime_magazine_post_settings',
        'choices' => array(
            'heading' => __('heading', 'prime-magazine') ,
            'author' => __('author', 'prime-magazine') ,
            'featured-image' => __('featured-image', 'prime-magazine') ,
            'content' => __('content', 'prime-magazine') ,
            'button' => __('button', 'prime-magazine') ,
        ) ,
    )));

    /** Post Settings Ends */

    /** Single Post Settings */
    $wp_customize->add_section(
        'prime_magazine_single_post_settings',
        array(
            'title' => esc_html__( 'Single Post Settings', 'prime-magazine' ),
            'priority' => 20,
            'capability' => 'edit_theme_options',
        )
    );

    /** Single Post Content control */
    $wp_customize->add_setting( 
        'prime_magazine_single_post_content_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_single_post_content_setting',
        array(
            'label'       => __( 'Show / Hide Single Post Content', 'prime-magazine' ),
            'section'     => 'prime_magazine_single_post_settings',
            'type'        => 'checkbox',
        )
    );

    /** Post Meta control */
    $wp_customize->add_setting( 
        'prime_magazine_single_post_meta_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_single_post_meta_setting',
        array(
            'label'       => __( 'Show / Hide Single Post Meta', 'prime-magazine' ),
            'section'     => 'prime_magazine_single_post_settings',
            'type'        => 'checkbox',
        )
    );

    /** Single Post Settings Ends */

        // Typography Settings Section
    $wp_customize->add_section('prime_magazine_typography_settings', array(
        'title'      => esc_html__('Typography Settings', 'prime-magazine'),
        'priority'   => 30,
        'capability' => 'edit_theme_options',
        'panel' => 'prime_magazine_home_general_settings',
    ));

    // Array of fonts to choose from
    $font_choices = array(
        ''               => __('Select', 'prime-magazine'),
        'Arial'          => 'Arial, sans-serif',
        'Verdana'        => 'Verdana, sans-serif',
        'Helvetica'      => 'Helvetica, sans-serif',
        'Times New Roman'=> '"Times New Roman", serif',
        'Georgia'        => 'Georgia, serif',
        'Courier New'    => '"Courier New", monospace',
        'Trebuchet MS'   => '"Trebuchet MS", sans-serif',
        'Tahoma'         => 'Tahoma, sans-serif',
        'Palatino'       => '"Palatino Linotype", serif',
        'Garamond'       => 'Garamond, serif',
        'Impact'         => 'Impact, sans-serif',
        'Comic Sans MS'  => '"Comic Sans MS", cursive, sans-serif',
        'Lucida Sans'    => '"Lucida Sans Unicode", sans-serif',
        'Arial Black'    => '"Arial Black", sans-serif',
        'Gill Sans'      => '"Gill Sans", sans-serif',
        'Segoe UI'       => '"Segoe UI", sans-serif',
        'Open Sans'      => '"Open Sans", sans-serif',
        'Roboto'         => 'Roboto, sans-serif',
        'Lato'           => 'Lato, sans-serif',
        'Montserrat'     => 'Montserrat, sans-serif',
        'Libre Baskerville' => 'Libre Baskerville',
    );

    // Heading Font Setting
    $wp_customize->add_setting('prime_magazine_heading_font_family', array(
        'default'           => '',
        'sanitize_callback' => 'prime_magazine_sanitize_choicess',
    ));
    $wp_customize->add_control('prime_magazine_heading_font_family', array(
        'type'    => 'select',
        'choices' => $font_choices,
        'label'   => __('Select Font for Heading', 'prime-magazine'),
        'section' => 'prime_magazine_typography_settings',
    ));

    // Body Font Setting
    $wp_customize->add_setting('prime_magazine_body_font_family', array(
        'default'           => '',
        'sanitize_callback' => 'prime_magazine_sanitize_choicess',
    ));
    $wp_customize->add_control('prime_magazine_body_font_family', array(
        'type'    => 'select',
        'choices' => $font_choices,
        'label'   => __('Select Font for Body', 'prime-magazine'),
        'section' => 'prime_magazine_typography_settings',
    ));

    /** Typography Settings Section End */

    /** General Settings */
    $wp_customize->add_panel( 
        'prime_magazine_home_general_settings',
         array(
            'priority' => 9,
            'capability' => 'edit_theme_options',
            'title' => esc_html__( 'General Settings', 'prime-magazine' ),
            'description' => esc_html__( 'Customize General Settings', 'prime-magazine' ),
        ) 
    );

    /** General Settings */
    $wp_customize->add_section(
        'prime_magazine_general_settings',
        array(
            'title' => esc_html__( 'Loader Settings', 'prime-magazine' ),
            'priority' => 20,
            'capability' => 'edit_theme_options',
            'panel' => 'prime_magazine_home_general_settings',
        )
    );

    /** Preloader control */
    $wp_customize->add_setting( 
        'prime_magazine_preloader_setting', 
        array(
            'default'           => false,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_preloader_setting',
        array(
            'label'       => __( 'Show / Hide Preloader', 'prime-magazine' ),
            'section'     => 'prime_magazine_general_settings',
            'type'        => 'checkbox',
        )
    );
    $wp_customize->add_setting('prime_magazine_loader_layout_setting', array(
        'default' => 'load',
        'sanitize_callback' => 'sanitize_text_field',
    ));

    // Add control for loader layout
    $wp_customize->add_control('prime_magazine_loader_layout_control', array(
        'label' => __('Preloader Layout', 'prime-magazine'),
        'section' => 'prime_magazine_general_settings',
        'settings' => 'prime_magazine_loader_layout_setting',
        'type' => 'select',
        'choices' => array(
            'load' => __('Preloader 1', 'prime-magazine'),
            'load-one' => __('Preloader 2', 'prime-magazine'),
            'ctn-preloader' => __('Preloader 3', 'prime-magazine'),
        ),
    ));

    $wp_customize->add_setting('prime_magazine_theme_width',array(
        'default' => 'full-width',
        'sanitize_callback' => 'prime_magazine_sanitize_theme_width'
    ));
    $wp_customize->add_control('prime_magazine_theme_width',array(
        'type' => 'select',
        'label' => __('Theme Width Option','prime-magazine'),
        'section' => 'prime_magazine_general_settings',
        'choices' => array(
            'full-width' => __('Fullwidth','prime-magazine'),
            'container' => __('Container','prime-magazine'),
            'container-fluid' => __('Container Fluid','prime-magazine'),
        ),
    ) );

    /** General Settings Ends */

    /** Header Section Settings */
    $wp_customize->add_section(
        'prime_magazine_header_section_settings',
        array(
            'title' => esc_html__( 'Header Section Settings', 'prime-magazine' ),
            'priority' => 30,
            'capability' => 'edit_theme_options',
            'panel' => 'prime_magazine_home_page_settings',
        )
    );

    /** Header control */
    $wp_customize->add_setting( 
        'prime_magazine_header_setting', 
        array(
            'default'           => false,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_header_setting',
        array(
            'label'       => __( 'Show / Hide Header', 'prime-magazine' ),
            'section'     => 'prime_magazine_header_section_settings',
            'type'        => 'checkbox',
        )
    );

    /**  User Link */
    $wp_customize->add_setting(
        'prime_magazine_top_header_user',
        array( 
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh'
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_top_header_user',
        array(
            'label' => esc_html__( 'Add User Link', 'prime-magazine' ),
            'section' => 'prime_magazine_header_section_settings',
            'type' => 'url',
        )
    );

    /**  Subscribe Link */
    $wp_customize->add_setting(
        'prime_magazine_top_header_subscribe',
        array( 
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh'
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_top_header_subscribe',
        array(
            'label' => esc_html__( 'Add Subscribe Link', 'prime-magazine' ),
            'section' => 'prime_magazine_header_section_settings',
            'type' => 'url',
        )
    );

    /** Sticky Header control */
    $wp_customize->add_setting( 
        'prime_magazine_sticky_header', 
        array(
            'default' => false,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_sticky_header',
        array(
            'label'       => __( 'Show Sticky Header', 'prime-magazine' ),
            'section'     => 'prime_magazine_header_section_settings',
            'type'        => 'checkbox',
        )
    );

     // Add Setting for Menu Font Weight
    $wp_customize->add_setting( 'prime_magazine_menu_font_weight', array(
        'default'           => '600',
        'sanitize_callback' => 'prime_magazine_sanitize_font_weight',
    ) );

    // Add Control for Menu Font Weight
    $wp_customize->add_control( 'prime_magazine_menu_font_weight', array(
        'label'    => __( 'Menu Font Weight', 'prime-magazine' ),
        'section'  => 'prime_magazine_header_section_settings',
        'type'     => 'select',
        'choices'  => array(
            '100' => __( '100 - Thin', 'prime-magazine' ),
            '200' => __( '200 - Extra Light', 'prime-magazine' ),
            '300' => __( '300 - Light', 'prime-magazine' ),
            '400' => __( '400 - Normal', 'prime-magazine' ),
            '500' => __( '500 - Medium', 'prime-magazine' ),
            '600' => __( '600 - Semi Bold', 'prime-magazine' ),
            '700' => __( '700 - Bold', 'prime-magazine' ),
            '800' => __( '800 - Extra Bold', 'prime-magazine' ),
            '900' => __( '900 - Black', 'prime-magazine' ),
        ),
    ) );

    // Add Setting for Menu Text Transform
    $wp_customize->add_setting( 'prime_magazine_menu_text_transform', array(
        'default'           => 'capitalize',
        'sanitize_callback' => 'prime_magazine_sanitize_text_transform',
    ) );

    // Add Control for Menu Text Transform
    $wp_customize->add_control( 'prime_magazine_menu_text_transform', array(
        'label'    => __( 'Menu Text Transform', 'prime-magazine' ),
        'section'  => 'prime_magazine_header_section_settings',
        'type'     => 'select',
        'choices'  => array(
            'none'       => __( 'None', 'prime-magazine' ),
            'capitalize' => __( 'Capitalize', 'prime-magazine' ),
            'uppercase'  => __( 'Uppercase', 'prime-magazine' ),
            'lowercase'  => __( 'Lowercase', 'prime-magazine' ),
        ),
    ) );

    $wp_customize->add_setting('prime_magazine_menus_style',array(
        'default' => '',
        'sanitize_callback' => 'prime_magazine_sanitize_choices'
	));
	$wp_customize->add_control('prime_magazine_menus_style',array(
        'type' => 'select',
		'label' => __('Menu Hover Style','prime-magazine'),
		'section' => 'prime_magazine_header_section_settings',
		'choices' => array(
         'None' => __('None','prime-magazine'),
         'Zoom In' => __('Zoom In','prime-magazine'),
      ),
	));

    /** Header Section Settings End */

    /** Social Section Settings */
    $wp_customize->add_section(
        'prime_magazine_social_section_settings',
        array(
            'title' => esc_html__( 'Social Media Section Settings', 'prime-magazine' ),
            'priority' => 30,
            'capability' => 'edit_theme_options',
            'panel' => 'prime_magazine_home_page_settings',
        )
    );

    /** Social Section control */
    $wp_customize->add_setting( 
        'prime_magazine_social_icon_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_social_icon_setting',
        array(
            'label'       => __( 'Show / Hide Social Icon', 'prime-magazine' ),
            'section'     => 'prime_magazine_social_section_settings',
            'type'        => 'checkbox',
        )
    );

    /**  Social Link 1 */
    $wp_customize->add_setting(
        'prime_magazine_social_link_1',
        array( 
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh'
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_social_link_1',
        array(
            'label' => esc_html__( 'Add Facebook Link', 'prime-magazine' ),
            'section' => 'prime_magazine_social_section_settings',
            'type' => 'url',
        )
    );

    $wp_customize->add_setting('prime_magazine_face_icon',array(
        'default'   => 'fab fa-facebook',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control(new Prime_Magazine_Changeable_Icon(
        $wp_customize,'prime_magazine_face_icon',array(
        'label' => __('Facebook Icon','prime-magazine'),
        'transport' => 'refresh',
        'section'   => 'prime_magazine_social_section_settings',
        'type'      => 'icon'
    )));

    /**  Social Link 2 */
    $wp_customize->add_setting(
        'prime_magazine_social_link_2',
        array( 
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh'
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_social_link_2',
        array(
            'label' => esc_html__( 'Add Twitter Link', 'prime-magazine' ),
            'section' => 'prime_magazine_social_section_settings',
            'type' => 'url',
        )
    );

    $wp_customize->add_setting('prime_magazine_twit_icon',array(
        'default'   => 'fab fa-twitter',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control(new Prime_Magazine_Changeable_Icon(
        $wp_customize,'prime_magazine_twit_icon',array(
        'label' => __('Twitter Icon','prime-magazine'),
        'transport' => 'refresh',
        'section'   => 'prime_magazine_social_section_settings',
        'type'      => 'icon'
    )));


    /**  Social Link 3 */
    $wp_customize->add_setting(
        'prime_magazine_social_link_3',
        array( 
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh'
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_social_link_3',
        array(
            'label' => esc_html__( 'Add Instagram Link', 'prime-magazine' ),
            'section' => 'prime_magazine_social_section_settings',
            'type' => 'url',
        )
    );

    $wp_customize->add_setting('prime_magazine_ints_icon',array(
        'default'   => 'fab fa-instagram',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control(new Prime_Magazine_Changeable_Icon(
        $wp_customize,'prime_magazine_ints_icon',array(
        'label' => __('Instagram Icon','prime-magazine'),
        'transport' => 'refresh',
        'section'   => 'prime_magazine_social_section_settings',
        'type'      => 'icon'
    )));

    /**  Social Link 4 */
    $wp_customize->add_setting(
        'prime_magazine_social_link_4',
        array( 
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh'
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_social_link_4',
        array(
            'label' => esc_html__( 'Add Pintrest Link', 'prime-magazine' ),
            'section' => 'prime_magazine_social_section_settings',
            'type' => 'url',
        )
    );

    $wp_customize->add_setting('prime_magazine_pint_icon',array(
        'default'   => 'fab fa-pinterest-p',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control(new Prime_Magazine_Changeable_Icon(
        $wp_customize,'prime_magazine_pint_icon',array(
        'label' => __('Pintrest Icon','prime-magazine'),
        'transport' => 'refresh',
        'section'   => 'prime_magazine_social_section_settings',
        'type'      => 'icon'
    )));


    /** Social Section Settings End */

    /** Home Page Settings */
    $wp_customize->add_panel( 
        'prime_magazine_home_page_settings',
         array(
            'priority' => 9,
            'capability' => 'edit_theme_options',
            'title' => esc_html__( 'Home Page Settings', 'prime-magazine' ),
            'description' => esc_html__( 'Customize Home Page Settings', 'prime-magazine' ),
        ) 
    );

    /** Slider Section Settings */
    $wp_customize->add_section(
        'prime_magazine_slider_section_settings',
        array(
            'title' => esc_html__( 'Slider Section Settings', 'prime-magazine' ),
            'priority' => 30,
            'capability' => 'edit_theme_options',
            'panel' => 'prime_magazine_home_page_settings',
        )
    );

    /** Slider Section control */
    $wp_customize->add_setting( 
        'prime_magazine_slider_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_slider_setting',
        array(
            'label'       => __( 'Show / Hide Slider', 'prime-magazine' ),
            'section'     => 'prime_magazine_slider_section_settings',
            'type'        => 'checkbox',
        )
    );
    
    $categories = get_categories();
        $cat_posts = array();
            $i = 0;
            $cat_posts[]='Select';
        foreach($categories as $category){
            if($i==0){
            $default = $category->slug;
            $i++;
        }
        $cat_posts[$category->slug] = $category->name;
    }

    $wp_customize->add_setting(
        'prime_magazine_blog_slide_category',
        array(
            'default'   => 'select',
            'sanitize_callback' => 'prime_magazine_sanitize_choices',
        )
    );
    $wp_customize->add_control(
        'prime_magazine_blog_slide_category',
        array(
            'type'    => 'select',
            'choices' => $cat_posts,
            'label' => __('Select Category to display Latest Post','prime-magazine'),
            'section' => 'prime_magazine_slider_section_settings',
        )
    );

    $live_update_categories = get_categories();
        $live_update_posts = array();
            $i = 0;
            $live_update_posts[]='Select';
        foreach($live_update_categories as $category){
            if($i==0){
            $default = $category->slug;
            $i++;
        }
        $live_update_posts[$category->slug] = $category->name;
    }

    $wp_customize->add_setting(
        'prime_magazine_live_update_category',
        array(
            'default'   => 'select',
            'sanitize_callback' => 'prime_magazine_sanitize_choices',
        )
    );
    $wp_customize->add_control(
        'prime_magazine_live_update_category',
        array(
            'type'    => 'select',
            'choices' => $live_update_posts,
            'label' => __('Select Category to display live updates.','prime-magazine'),
            'section' => 'prime_magazine_slider_section_settings',
        )
    );

    /** Slider Button control */
    $wp_customize->add_setting( 
        'prime_magazine_slider_button_setting', 
        array(
            'default'           => false,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_slider_button_setting',
        array(
            'label'       => __( 'Show / Hide Slider Button', 'prime-magazine' ),
            'section'     => 'prime_magazine_slider_section_settings',
            'type'        => 'checkbox',
        )
    );

    /** Trending Post Section Settings */
    
    $wp_customize->add_section( 'prime_magazine_section_trending_post',
        array(
        'title'      => __( 'Trending Post Section', 'prime-magazine' ),
        'priority'   => 110,
        'capability' => 'edit_theme_options',
        'panel'      => 'prime_magazine_home_page_settings',
        )
    );

    /** Trending Post Section control */
    $wp_customize->add_setting( 
        'prime_magazine_trending_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_trending_setting',
        array(
            'label'       => __( 'Show / Hide Trending Post', 'prime-magazine' ),
            'section'     => 'prime_magazine_section_trending_post',
            'type'        => 'checkbox',
        )
    );

    /**  Heading **/
    $wp_customize->add_setting(
        'prime_magazine_trending_post_title',
        array( 
            'default' => '',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh'
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_trending_post_title',
        array(
            'label' => esc_html__( 'Add Section Heading', 'prime-magazine' ),
            'section' => 'prime_magazine_section_trending_post',
            'type' => 'text',
        )
    );

    $categories = get_categories();
        $cat_posts = array();
            $i = 0;
            $cat_posts[]='Select';
        foreach($categories as $category){
            if($i==0){
            $default = $category->slug;
            $i++;
        }
        $cat_posts[$category->slug] = $category->name;
    }

    $wp_customize->add_setting(
        'prime_magazine_trending_post_slider_args',
        array(
            'default'   => 'select',
            'sanitize_callback' => 'prime_magazine_sanitize_choices',
        )
    );
    $wp_customize->add_control(
        'prime_magazine_trending_post_slider_args',
        array(
            'type'    => 'select',
            'choices' => $cat_posts,
            'label' => __('Select Category to display Trending Post','prime-magazine'),
            'section' => 'prime_magazine_section_trending_post',
        )
    );

    /** Home Page Settings Ends */
    
    /** Footer Section */
    $wp_customize->add_section(
        'prime_magazine_footer_section',
        array(
            'title' => __( 'Footer Settings', 'prime-magazine' ),
            'priority' => 70,
            'panel' => 'prime_magazine_home_page_settings',
        )
    );
    
    /** Footer Copyright control */
    $wp_customize->add_setting( 
        'prime_magazine_footer_copyright_setting', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_footer_copyright_setting',
        array(
            'label'       => __( 'Show / Hide Footer Copyright', 'prime-magazine' ),
            'section'     => 'prime_magazine_footer_section',
            'type'        => 'checkbox',
        )
    );
    
    /** Copyright Text */
    $wp_customize->add_setting(
        'prime_magazine_footer_copyright_text',
        array(
            'default' => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );
    
    $wp_customize->add_control(
        'prime_magazine_footer_copyright_text',
        array(
            'label' => __( 'Copyright Info', 'prime-magazine' ),
            'section' => 'prime_magazine_footer_section',
            'type' => 'text',
        )
    );  

    /* Footer Background Color*/
    $wp_customize->add_setting(
        'footer_background_color',
        array(
            'default' => '',
            'sanitize_callback' => 'sanitize_hex_color',
        )
    );
    $wp_customize->add_control(
        new WP_Customize_Color_Control(
            $wp_customize,
            'footer_background_color',
            array(
                'label' => __('Footer Widget Area Background Color', 'prime-magazine'),
                'section' => 'prime_magazine_footer_section',
                'type' => 'color',
            )
        )
    );

    $wp_customize->add_setting('footer_background_image',
        array(
        'default' => '',
        'capability' => 'edit_theme_options',
        'sanitize_callback' => 'absint',
        )
    );

    $wp_customize->add_control(
         new WP_Customize_Cropped_Image_Control($wp_customize, 'footer_background_image',
            array(
                'label' => esc_html__('Footer Background Image', 'prime-magazine'),
                'description' => sprintf(esc_html__('Recommended Size %1$s px X %2$s px', 'prime-magazine'), 1024, 800),
                'section' => 'prime_magazine_footer_section',
                'width' => 1024,
                'height' => 800,
                'flex_width' => true,
                'flex_height' => true,
            )
        )
    );

    /** Footer Background Image Attachment */
    $wp_customize->add_setting('prime_magazine_background_attatchment', array(
        'default'           => 'scroll',
        'sanitize_callback' => 'prime_magazine_sanitize_choices',
    ));

    $wp_customize->add_control('prime_magazine_background_attatchment', array(
        'label'    => __('Footer Background Attachment', 'prime-magazine'),
        'section'  => 'prime_magazine_footer_section',
        'settings' => 'prime_magazine_background_attatchment',
        'type'     => 'select',
        'choices'  => array(
            'fixed' => __('fixed','prime-magazine'),
            'scroll' => __('scroll','prime-magazine'),
        ),
    ));

    /** Scroll To Top control */
    $wp_customize->add_setting( 
        'prime_magazine_scroll_to_top', 
        array(
            'default'           => true,
            'sanitize_callback' => 'prime_magazine_sanitize_checkbox',
        ) 
    );

    $wp_customize->add_control(
        'prime_magazine_scroll_to_top',
        array(
            'label'       => __( 'Show / Hide Scroll To Top', 'prime-magazine' ),
            'section'     => 'prime_magazine_footer_section',
            'type'        => 'checkbox',
        )
    );

    $wp_customize->add_setting('prime_magazine_scroll_top_alignment',array(
        'default' => 'right-align',
        'sanitize_callback' => 'prime_magazine_sanitize_scroll_top_alignment'
    ));
    $wp_customize->add_control('prime_magazine_scroll_top_alignment',array(
        'type' => 'select',
        'label' => __('Scroll Top Alignment','prime-magazine'),
        'section' => 'prime_magazine_footer_section',
        'choices' => array(
            'right-align' => __('Right Alignment','prime-magazine'),
            'center-align' => __('Center Alignment','prime-magazine'),
            'left-align' => __('Left Alignment','prime-magazine'),
        ),
    ) );

    /** Scroll to top button shape */
    $wp_customize->add_setting('prime_magazine_scroll_to_top_radius', array(
        'default'           => 'curved-box',
        'sanitize_callback' => 'prime_magazine_sanitize_choices',
    ));

    $wp_customize->add_control('prime_magazine_scroll_to_top_radius', array(
        'label'    => __('Scroll Top Button Shape', 'prime-magazine'),
        'section'  => 'prime_magazine_footer_section',
        'settings' => 'prime_magazine_scroll_to_top_radius',
        'type'     => 'select',
        'choices'  => array(
            'box'        => __( 'Box', 'prime-magazine' ),
            'curved-box' => __( 'Curved Box', 'prime-magazine' ),
            'circle'     => __( 'Circle', 'prime-magazine' ),
        ),
    ));

    // 404 PAGE SETTINGS
    $wp_customize->add_section(
        'prime_magazine_404_section',
        array(
            'title' => __( '404 Page Settings', 'prime-magazine' ),
            'priority' => 70,
            'panel' => 'prime_magazine_home_general_settings',
        )
    );
   
    $wp_customize->add_setting('404_page_image', array(
        'default' => '',
        'transport' => 'refresh',
        'sanitize_callback' => 'esc_url_raw', // Sanitize as URL
    ));

    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, '404_page_image', array(
        'label' => __('404 Page Image', 'prime-magazine'),
        'section' => 'prime_magazine_404_section',
        'settings' => '404_page_image',
    )));

    $wp_customize->add_setting('404_pagefirst_header', array(
        'default' => __('404', 'prime-magazine'),
        'transport' => 'refresh',
        'sanitize_callback' => 'sanitize_text_field', // Sanitize as text field
    ));

    $wp_customize->add_control('404_pagefirst_header', array(
        'type' => 'text',
        'label' => __('Heading', 'prime-magazine'),
        'section' => 'prime_magazine_404_section',
    ));

    // Setting for 404 page header
    $wp_customize->add_setting('404_page_header', array(
        'default' => __('Sorry, that page can\'t be found!', 'prime-magazine'),
        'transport' => 'refresh',
        'sanitize_callback' => 'sanitize_text_field', // Sanitize as text field
    ));

    $wp_customize->add_control('404_page_header', array(
        'type' => 'text',
        'label' => __('Heading', 'prime-magazine'),
        'section' => 'prime_magazine_404_section',
    ));
}
add_action( 'customize_register', 'prime_magazine_customize_register' );
endif;

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function prime_magazine_customize_preview_js() {
    // Use minified libraries if SCRIPT_DEBUG is false
    $prime_magazine_build  = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '/build' : '';
    $prime_magazine_suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
	wp_enqueue_script( 'prime_magazine_customizer', get_template_directory_uri() . '/js' . $prime_magazine_build . '/customizer' . $prime_magazine_suffix . '.js', array( 'customize-preview' ), '20130508', true );
}
add_action( 'customize_preview_init', 'prime_magazine_customize_preview_js' );