<?php
/**
 * About Settings
 *
 * @package Travel Tour
 */
add_action( 'customize_register', 'travel_tour_customize_register_cta_section' );

function travel_tour_customize_register_cta_section( $wp_customize ) {

  $wp_customize->add_section( 'travel_tour_about_sections', array(
    'title'          => esc_html__( 'CTA Section', 'travel-tour' ),
    'description'    => esc_html__( 'CTA section :', 'travel-tour' ),
    'panel'          => 'travel_tour_homepage_panel',
    'priority'       => 7,
  ) );

  $wp_customize->add_setting( 'about_display_option', array(
      'sanitize_callback'     =>  'travel_tour_sanitize_checkbox',
      'default'               =>  true
  ) );

  $wp_customize->add_control( new Travel_Tour_Toggle_Control(
    $wp_customize, 'about_display_option', array(
      'label' => esc_html__( 'Hide / Show','travel-tour' ),
      'section' => 'travel_tour_about_sections',
      'settings' => 'about_display_option',
      'type'=> 'toggle',
    ) 
  ) );

  $wp_customize->selective_refresh->add_partial( 'about_display_option', array(
      'selector' => '.about-us .container-xl',
  ) );

  $wp_customize->add_setting('about_page', array(
    'sanitize_callback' => 'travel_tour_sanitize_select',
    'default' => ''
  ));

  $page_query = get_pages();
  $pages = array();
  $pages[''] = esc_attr__("-- No page --", 'travel-tour');
  foreach ($page_query as $page) {
      $pages[ $page->post_name ] = $page->post_title;
  }

  $wp_customize->add_control(new Travel_Tour_Select_Control
    ($wp_customize, 'about_page', array(
      'label' => esc_html__('Select a page :', 'travel-tour'),
      'section' => 'travel_tour_about_sections',
      'settings' => 'about_page',
      'type' => 'select',
      'choices' => $pages,
    )
  ));

  $wp_customize->add_setting('travel_tour_cta_sections_text_message', array(
    'sanitize_callback' => 'wp_kses_post',
    'default' => ''
  ));

  $wp_customize->add_control( new Travel_Tour_Text_Message_Control(
    $wp_customize, 'travel_tour_cta_sections_text_message', array(
      'section' => 'travel_tour_about_sections',
      'settings' => 'travel_tour_cta_sections_text_message',
      'title' => esc_html__('Or set custom content :', 'travel-tour'),
    ) 
  ) );

  $wp_customize->add_setting( 'travel_tour_cta_section_title', array(
    'sanitize_callback'     =>  'sanitize_text_field',
    'default'               =>  ''
  ) );

  $wp_customize->add_control( 'travel_tour_cta_section_title', array(
    'label' => esc_html__( 'Title', 'travel-tour' ),
    'section' => 'travel_tour_about_sections',
    'settings' => 'travel_tour_cta_section_title',
    'type'=> 'text',
  ) );

  $wp_customize->selective_refresh->add_partial( 'travel_tour_cta_section_title', array(
      'selector' => '.about-us h2',
  ) );

  $wp_customize->add_setting( 'travel_tour_cta_section_excerpt', array(
    'sanitize_callback' => 'sanitize_textarea_field',
    'default' =>  ''
  ) );

  $wp_customize->add_control( 'travel_tour_cta_section_excerpt', array(
    'label' => esc_html__( 'Description', 'travel-tour' ),
    'section' => 'travel_tour_about_sections',
    'settings' => 'travel_tour_cta_section_excerpt',
    'type'=> 'textarea',
  ) );

  $wp_customize->selective_refresh->add_partial( 'travel_tour_cta_section_excerpt', array(
    'selector' => '.about-us p',
  ) );

  $wp_customize->add_setting( 'travel_tour_cta_section_button_link', array(
    'sanitize_callback'     =>  'esc_url_raw',
    'default'               =>  ''
  ) );

  $wp_customize->add_control( 'travel_tour_cta_section_button_link', array(
    'label' => esc_html__( 'CTA Link', 'travel-tour' ),
    'section' => 'travel_tour_about_sections',
    'settings' => 'travel_tour_cta_section_button_link',
    'type'=> 'text',
  ) );

  $wp_customize->selective_refresh->add_partial( 'travel_tour_cta_section_button_link', array(
    'selector' => '.about-us a',
  ) );

  $wp_customize->add_setting( 'travel_tour_cta_section_button_label', array(
    'sanitize_callback'     =>  'sanitize_text_field',
    'default'               =>  ''
  ) );

  $wp_customize->add_control( 'travel_tour_cta_section_button_label', array(
    'label' => esc_html__( 'CTA Label', 'travel-tour' ),
    'section' => 'travel_tour_about_sections',
    'settings' => 'travel_tour_cta_section_button_label',
    'type'=> 'text',
  ) );

  $wp_customize->add_setting('travel_tour_cta_section_image', array(
    'transport' => 'refresh',
    'sanitize_callback' =>  'travel_tour_sanitize_file',
  ));

  $wp_customize->add_control( new WP_Customize_Image_Control(
    $wp_customize, 'travel_tour_cta_section_image', array(
      'label'             => __('Image', 'travel-tour'),
      'section'           => 'travel_tour_about_sections',
      'settings'          => 'travel_tour_cta_section_image',
    )
  ));

}