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

add_action( 'customize_register', 'social_charity_footer_settings_register' );

function social_charity_footer_settings_register( $wp_customize ) {
  require get_template_directory() .'/inc/repeater/class-repeater-settings.php';
  require get_template_directory() .'/inc/repeater/class-control-repeater.php';

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

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

 /**
 * Enable/Disable for footer top
 *
 * @since 1.0.0
 */
 $wp_customize->add_setting(
  'social_charity_footer_top_enable',
  array(
    'default'           => 0,
    'sanitize_callback' => 'social_charity_sanitize_checkbox',
  )
);

 $wp_customize->add_control(
  'social_charity_footer_top_enable',
  array(
    'section'     => 'social_charity_footer_top_section',
    'label'       => __( 'Enable/Disable for Footer Top Newsletter', 'social-charity' ),
    'type'        => 'checkbox'
  )       
);

// Newsletter Title
 $wp_customize->add_setting('social_charity_footer_top_newsletter_title',array(
  'default'       =>      '',
  'sanitize_callback'     =>  'sanitize_text_field'
));

 $wp_customize->add_control('social_charity_footer_top_newsletter_title',array(
  'section'       =>      'social_charity_footer_top_section',
  'label'         =>      __('Newsletter Title', 'social-charity'),
  'description'   =>      __('Eg:- Sign Up For newsletter', 'social-charity'),
  'type'          =>      'text',
  'settings'    =>    'social_charity_footer_top_newsletter_title'
));


// Newsletter Description
 $wp_customize->add_setting('social_charity_footer_top_newsletter_description',array(
  'default'       =>      '',
  'sanitize_callback'     =>  'sanitize_text_field'
));

 $wp_customize->add_control('social_charity_footer_top_newsletter_description',array(
  'section'       =>      'social_charity_footer_top_section',
  'label'         =>      __('Newsletter Description', 'social-charity'),
  'description'   =>      __('Eg:- Submit your email and stay in touch by notify our news & update regularly', 'social-charity'),
  'type'          =>      'text',
  'settings'    =>    'social_charity_footer_top_newsletter_description'
));


// Newsletter Form Shortcode Descriptions
 $wp_customize->add_setting('social_charity_top_header_newsletter_shortcode',array(
  'default'       =>      '',
  'sanitize_callback'     =>  'sanitize_text_field'
));
 $wp_customize->add_control('social_charity_top_header_newsletter_shortcode',array(
  'section'       =>      'social_charity_footer_top_section',
  'label'                 =>  __( 'Use Shortcode for newsletter form', 'social-charity' ),
  /* translators: %s: Description */ 
  'description'           => sprintf( __( 'Use Newsletter Plugins shortcode: Eg: %1$s. %2$s See more here %3$s', 'social-charity' ), '[newsletter_form type="minimal"]','<a href="'.esc_url('https://wordpress.org/plugins/newsletter/').'" target="_blank">','</a>' ),
  'type'          =>      'text',
  'settings'    =>    'social_charity_top_header_newsletter_shortcode'
));


 /*----------------------------------------------------------------------------------------------------------------------------------------*/
  /**
     * Footer Middle section
     *
     * @since 1.0.0
     */
  $wp_customize->add_section(
    'social_charity_footer_middle_section',
    array(
      'priority'       => 2,
      'panel'          => 'social_charity_footer_settings_panel',
      'capability'     => 'edit_theme_options',
      'theme_supports' => '',
      'title'          => __( 'Footer Middle Section', 'social-charity' ),
      'description'    => __( 'Managed the content display at Footer Middle section.', 'social-charity' ),
    )
  );

 /**
 * Enable/Disable for Footer Middle section
 *
 * @since 1.0.0
 */
 $wp_customize->add_setting(
  'social_charity_volunteer_enable',
  array(
    'default'           => 0,
    'sanitize_callback' => 'social_charity_sanitize_checkbox',
  )
);

class Social_Charity_Widget_Page_link extends WP_Customize_Control {
    public $type = 'customtext';
    public $extra = ''; // we add this for the extra description
    public function render_content() {
    ?>
    <label>            
        <a href="<?php echo esc_url( 'widgets.php' ); ?>" target='_blank'><?php echo esc_html( $this->label ); ?></a>
        <span><?php echo esc_html( $this->extra ); ?></span>         
    </label>
    <?php
    }
}
$wp_customize->add_setting('social_charity_go_to_widget', array(
  'default' => '',
  'type' => 'customtext',
  'capability' => 'edit_theme_options',
  'transport' => 'refresh',
  'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( new Social_Charity_Widget_Page_link( $wp_customize, 'social_charity_go_to_widget', array(
    'label' => esc_attr__( 'Go to Widgets Page', 'social-charity' ),
    'section' => 'social_charity_footer_middle_section',
    'settings' => 'social_charity_go_to_widget',
    'extra' => esc_attr__( 'click here', 'social-charity' )
    ) ) 
);


 /*----------------------------------------------------------------------------------------------------------------------------------------*/
  /**
     * Footer Bottom section
     *
     * @since 1.0.0
     */
  $wp_customize->add_section(
    'social_charity_footer_bottom_section',
    array(
      'priority'       => 3,
      'panel'          => 'social_charity_footer_settings_panel',
      'capability'     => 'edit_theme_options',
      'theme_supports' => '',
      'title'          => __( 'Footer Bottom Section', 'social-charity' ),
      'description'    => __( 'Managed the content display at Footer Bottom section.', 'social-charity' ),
    )
  );


  
  /**Footer Social media  Enable/Disable  */
  $wp_customize->add_setting(
    'footer_social_media_enable',
    array(
      'default'           => 0,
      'sanitize_callback' => 'social_charity_sanitize_checkbox',
    )
  );

  $wp_customize->add_control(
    'footer_social_media_enable',
    array(
      'section'     => 'social_charity_footer_bottom_section',
      'label'       => __( 'Social Links', 'social-charity' ),
      'description' => __( 'Enable/Disable social links in Footer.', 'social-charity' ),
      'type'        => 'checkbox'
    )       
  );


  /** Social Links */
  $wp_customize->add_setting( 
    new Social_Charity_Repeater_Setting( 
      $wp_customize, 
      'social_charity_social_links', 
      array(
        'default' => array(
          array(
            'font' => 'fa fa-facebook',
            'link' => 'https://www.facebook.com/',                        
          ),
          array(
            'font' => 'fa fa-linkedin',
            'link' => 'https://www.linkedin.com/',
          ),
          array(
            'font' => 'fa fa-twitter',
            'link' => 'https://twitter.com/',
          ),
          array(
            'font' => 'fa fa-google-plus',
            'link' => 'https://plus.google.com',
          )
        ),
        'sanitize_callback' => array( 'Social_Charity_Repeater_Setting', 'sanitize_repeater_setting' ),
      ) 
    ) 
  );

  $wp_customize->add_control(
    new Social_Charity_Control_Repeater(
      $wp_customize,
      'social_charity_social_links',
      array(
        'section' => 'social_charity_footer_bottom_section',              
        'label'   => __( 'Social Links', 'social-charity' ),
        'fields'  => array(
          'font' => array(
            'type'        => 'font',
            'label'       => __( 'Font Awesome Icon', 'social-charity' ),
            'description' => __( 'Example: fa-facebook', 'social-charity' ),
          ),
          'link' => array(
            'type'        => 'url',
            'label'       => __( 'Link', 'social-charity' ),
            'description' => __( 'Example: http://facebook.com', 'social-charity' ),
          )
        ),
        'row_label' => array(
          'type' => 'field',
          'value' => __( 'social', 'social-charity' ),
          'field' => 'link'
        )                        
      )
    )
  );
}