<?php
/**
 * Social_Charity Header Settings panel at Theme Customizer
 *
 * @package Social_Charity
 * @since 1.0.0
 */

add_action( 'customize_register', 'social_charity_header_settings_register' );

function social_charity_header_settings_register( $wp_customize ) {
  require get_template_directory() .'/inc/repeater/class-repeater-settings.php';
  require get_template_directory() .'/inc/repeater/class-control-repeater.php';
  $wp_customize->get_section( 'header_image' )->priority = '20';
  $wp_customize->get_section( 'header_image' )->title    = __( 'Header Image', 'social-charity' );
  $wp_customize->get_section( 'header_image' )->panel    = 'social_charity_header_settings_panel';

	/**
     * Add Header Settings Panel
     *
     * @since 1.0.0
     */
    $wp_customize->add_panel(
     'social_charity_header_settings_panel',
     array(
         'priority'       => 10,
         'capability'     => 'edit_theme_options',
         'theme_supports' => '',
         'title'          => __( 'Header Settings', 'social-charity' ),
     )
 );

    /*----------------------------------------------------------------------------------------------------------------------------------------*/
	/**
     * Top Header section
     *
     * @since 1.0.0
     */
    $wp_customize->add_section(
        'social_charity_top_header_section',
        array(
        	'priority'       => 5,
        	'panel'          => 'social_charity_header_settings_panel',
        	'capability'     => 'edit_theme_options',
        	'theme_supports' => '',
            'title'          => __( 'Top Header Section', 'social-charity' ),
            'description'    => __( 'Managed the content display at top header section.', 'social-charity' ),
        )
    );

    /*----------------------------------------------------------------------------------------------------------------------------------------*/
    /**
     *Enable/Disable Top Header section
     *
     * @since 1.0.0
     */
    $wp_customize->add_setting(
        'social_charity_top_header_enable',
        array(
            'default'           => 0,
            'sanitize_callback' => 'social_charity_sanitize_checkbox',
        )
    );
    
    $wp_customize->add_control(
        'social_charity_top_header_enable',
        array(
            'section'     => 'social_charity_top_header_section',
            'label'       => __( 'Enable/Disable top header', 'social-charity' ),
            'type'        => 'checkbox'
        )       
    );

    /*----------------------------------------------------------------------------------------------------------------------------------------*/
    /**
     *Login Page Link in Top Header section
     *
     * @since 1.0.0
     */
    $wp_customize->add_setting(
        'social_charity_login_page',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );
    
    $wp_customize->add_control(
        'social_charity_login_page',
        array(
            'section'     => 'social_charity_top_header_section',
            'label'       => __( 'Login Page URL', 'social-charity' ),
            'type'        => 'url'
        )       
    );

    /*----------------------------------------------------------------------------------------------------------------------------------------*/
    /**
     *Register Page Link in Top Header section
     *
     * @since 1.0.0
     */
    $wp_customize->add_setting(
        'social_charity_register_page',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );
    
    $wp_customize->add_control(
        'social_charity_register_page',
        array(
            'section'     => 'social_charity_top_header_section',
            'label'       => __( 'Register Page URL', 'social-charity' ),
            'type'        => 'url'
        )       
    );

    /** Top Header Contact info */
    $wp_customize->add_setting( 
        new Social_Charity_Repeater_Setting( 
            $wp_customize, 
            'top_header_contact_info_items', 
            array(
                'default' => array(
                    array(
                        'icon' => 'fa fa-phone',
                        'title' => ' + (123) 456 7890',
                    ),
                    array(
                        'icon' => 'fa fa-envelope',
                        'title' => 'info.demo@email.com',
                    )
                ),
                'sanitize_callback' => array( 'Social_Charity_Repeater_Setting', 'sanitize_repeater_setting' ),
            ) 
        ) 
    );

    $wp_customize->add_control(
        new Social_Charity_Control_Repeater(
            $wp_customize,
            'top_header_contact_info_items',
            array(
                'section' => 'social_charity_top_header_section',              
                'label'   => __( 'Top Header Contact items', 'social-charity' ),
                'fields'  => array(
                    'icon' => array(
                        'type'        => 'font',
                        'label'       => __( 'Font Awesome Icon', 'social-charity' ),
                    ),
                    'title' => array(
                        'type'        => 'text',
                        'label'       => __( 'Location Title', 'social-charity' ),
                    )
                ),
                'row_label' => array(
                    'type' => 'field',
                    'value' => __( 'contact', 'social-charity' ),
                    'field' => 'title'
                )                        
            )
        )
    );

}