<?php
/**
 * Theme Customizer Controls
 *
 * @package somalite
 */


if ( ! function_exists( 'somalite_customizer_page_register' ) ) :
function somalite_customizer_page_register( $wp_customize ) {
    
    // Page settings
    $wp_customize->add_section(
        'soma_page_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'theme_supports'=> '',
            'title'         => esc_html__( 'Page Settings', 'somalite' )
        )
    );

    // Title label
    $wp_customize->add_setting( 
        'somalite_label_page_title_settings', 
        array(
              'sanitize_callback' => 'somalite_sanitize_title',
        ) 
    );

    $wp_customize->add_control( 
        new Somalite_Title_Info_Control( $wp_customize, 'somalite_label_page_title_settings', 
        array(
            'label'       => esc_html__( 'Page Title Settings', 'somalite' ),
            'section'     => 'soma_page_settings',
            'type'        => 'somalite-title',
            'settings'    => 'somalite_label_page_title_settings',
        ) 
    ));

    // Background selection
    $wp_customize->add_setting(
        'sm_bg_radio',
        array(
            'type' => 'theme_mod',
            'default'           => 'color',
            'sanitize_callback' => 'somalite_sanitize_select'
        )
    );

    $wp_customize->add_control(
        'sm_bg_radio',
        array(
            'settings'      => 'sm_bg_radio',
            'section'       => 'soma_page_settings',
            'type'          => 'radio',
            'label'         => esc_html__( 'Choose Page Title Background Color or Background Image:', 'somalite' ),
            'description'   => esc_html__('This setting will change the background of the page title area.', 'somalite'),
            'choices' => array(
                            'color' => esc_html__('Background Color','somalite'),
                            'image' => esc_html__('Background Image','somalite'),
                            ),
        )
    );

    // Title label
    $wp_customize->add_setting( 
        'somalite_label_page_title_bg_color_settings', 
        array(
              'sanitize_callback' => 'somalite_sanitize_title',
        ) 
    );

    $wp_customize->add_control( 
        new Somalite_Title_Info_Control( $wp_customize, 'somalite_label_page_title_bg_color_settings', 
        array(
            'label'       => esc_html__( 'Page Title Background Color', 'somalite' ),
            'section'     => 'soma_page_settings',
            'type'        => 'somalite-title',
            'settings'    => 'somalite_label_page_title_bg_color_settings',
            'active_callback' => 'somalite_page_title_bg_color',
        ) 
    ));

    // Background color
    $wp_customize->add_setting(
        'sm_bg_color',
        array(
            'type' => 'theme_mod',
            'default'           => '#dd3333',
            'sanitize_callback' => 'sanitize_hex_color'
        )
    );

    $wp_customize->add_control(
        new WP_Customize_Color_Control(
        $wp_customize,
        'sm_bg_color',
        array(
        'label'      => esc_html__( 'Select Background Color', 'somalite' ),
        'description'   => esc_html__('This setting will add background color to the page title area if Background Color was selected above.', 'somalite'),
        'section'    => 'soma_page_settings',
        'settings'   => 'sm_bg_color',
        'active_callback' => 'somalite_page_title_bg_color',
        ) )
    );

     // Title label
    $wp_customize->add_setting( 
        'somalite_label_page_title_bg_image_settings', 
        array(
              'sanitize_callback' => 'somalite_sanitize_title',
        ) 
    );

    $wp_customize->add_control( 
        new Somalite_Title_Info_Control( $wp_customize, 'somalite_label_page_title_bg_image_settings', 
        array(
            'label'       => esc_html__( 'Page Title Background Image', 'somalite' ),
            'section'     => 'soma_page_settings',
            'type'        => 'somalite-title',
            'settings'    => 'somalite_label_page_title_bg_image_settings',
            'active_callback' => 'somalite_page_title_bg_image',
        ) 
    ));

    // Background Image
    $wp_customize->add_setting(
        'sm_bg_image',
        array(
            'type' => 'theme_mod',
            'sanitize_callback' => 'somalite_sanitize_image'
        )
    );

    $wp_customize->add_control(
      new WP_Customize_Image_Control(
          $wp_customize,
          'sm_bg_image',
          array(
              'settings'      => 'sm_bg_image',
              'section'       => 'soma_page_settings',
              'label'         => esc_html__( 'Select Background Image', 'somalite' ),
              'description'   => esc_html__('This setting will add the background image to the page title area if Background Image was selected above.', 'somalite'),
              'active_callback' => 'somalite_page_title_bg_image',
          )
      )
    );

    // Title label
    $wp_customize->add_setting( 
        'somalite_label_page_title_bg_overlay_settings', 
        array(
              'sanitize_callback' => 'somalite_sanitize_title',
        ) 
    );

    $wp_customize->add_control( 
        new Somalite_Title_Info_Control( $wp_customize, 'somalite_label_page_title_bg_overlay_settings', 
        array(
            'label'       => esc_html__( 'Dark Overlay Settings', 'somalite' ),
            'section'     => 'soma_page_settings',
            'type'        => 'somalite-title',
            'settings'    => 'somalite_label_page_title_bg_overlay_settings',
            'active_callback' => 'somalite_page_title_bg_image',
        ) 
    ));

    // overlay bg
    $wp_customize->add_setting(
        'sm_bg_radio_overlay',
        array(
            'type' => 'theme_mod',
            'default'           => true,
            'sanitize_callback' => 'somalite_sanitize_checkbox'
        )
    );

    $wp_customize->add_control( 
        new Somalite_Toggle_Control( $wp_customize, 'sm_bg_radio_overlay', 
        array(
            'section'     => 'soma_page_settings',
            'type'        => 'somalite-toggle',
            'settings'    => 'sm_bg_radio_overlay',
            'label'         => esc_html__( 'Add Dark Overlay over background Image:', 'somalite' ),
            'description'   => esc_html__('This setting will add the dark overlay over background image to the page title area if Background Image was selected above.', 'somalite'),
            'active_callback' => 'somalite_page_title_bg_image',
        ) 
    ));
    
}
endif;

add_action( 'customize_register', 'somalite_customizer_page_register' );