<?php
/**
 * Add custom settings and controls to the WordPress Customizer
 */
//---------------------Code to add the Upgrade to Pro button in the Customizer----------

function pawprints_blog_customize_register_btn( $wp_customize ) {
    $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
    $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
    $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

    get_template_part('inc/customizer-button/upsell-section');

    if ( isset( $wp_customize->selective_refresh ) ) {
        $wp_customize->selective_refresh->add_partial( 'blogname', array(
            'selector'        => '.site-title a',
            'render_callback' => 'pawprints_blog_customize_partial_blogname',
        ) );
        $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
            'selector'        => '.site-description',
            'render_callback' => 'pawprints_blog_customize_partial_blogdescription',
        ) );
    }

    $wp_customize->register_section_type( 'Pawprints_Blog_Customize_Upsell_Section' );

    // Register section.
    $wp_customize->add_section(
        new Pawprints_Blog_Customize_Upsell_Section(
            $wp_customize,
            'theme_upsell',
            array(
                'title'    => esc_html__( 'Pawprints Pro', 'pawprints-blog' ),
                'pro_text' => esc_html__( 'Upgrade To Pro', 'pawprints-blog' ),
                'pro_url'  => 'https://cawpthemes.com/pawprints-blog-premium-wordpress-theme/',
                'priority' => 1,
            )
        )
    );
}
add_action( 'customize_register', 'pawprints_blog_customize_register_btn' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function pawprints_blog_customize_partial_blogname() {
    bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function pawprints_blog_customize_partial_blogdescription() {
    bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function pawprints_blog_customize_preview_js() {
    wp_enqueue_script( 'pawprints-blog-customizer', get_template_directory_uri() . '/inc/customizer-button/customizer.js', array( 'customize-preview' ), '20151215', true );
}
add_action( 'customize_preview_init', 'pawprints_blog_customize_preview_js' );

/**
 * Customizer control scripts and styles.
 *
 * @since 1.0.0
 */
function pawprints_blog_customizer_control_scripts() {

    wp_enqueue_style( 'pawprints-blog-customize-controls', get_template_directory_uri() . '/inc/customizer-button/customize-controls.css', '', '1.0.0' );

    wp_enqueue_script( 'pawprints-blog-customize-controls', get_template_directory_uri() . '/inc/customizer-button/customize-controls.js', array( 'customize-controls' ), '1.0.0', true );
}
add_action( 'customize_controls_enqueue_scripts', 'pawprints_blog_customizer_control_scripts', 0 );


//----Code to add the Upgrade to Pro button in the Customizer End----------


//------------------Theme Information--------------------




function pawprints_blog_customize_register( $wp_customize ) {


  // Add a custom setting for the Site Identity color
  $wp_customize->add_setting( 'pawprints_blog_site_identity_color', array(
    'default' => '#996f23',
    'sanitize_callback' => 'sanitize_hex_color',
  ) );

  // Add a custom control for the primary color
  $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'pawprints_blog_site_identity_color', array(
    'label' => __( 'Site Identity Color', 'pawprints-blog' ),
    'section' => 'title_tagline',
    'settings' => 'pawprints_blog_site_identity_color',
  ) ) );


  // Add a custom setting for the Site Identity color
  $wp_customize->add_setting( 'pawprints_blog_site_identity_tagline_color', array(
    'default' => '#000',
    'sanitize_callback' => 'sanitize_hex_color',
  ) );

  // Add a custom control for the primary color
  $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'pawprints_blog_site_identity_tagline_color', array(
    'label' => __( 'Tagline Color', 'pawprints-blog' ),
    'section' => 'title_tagline',
    'settings' => 'pawprints_blog_site_identity_tagline_color',
  ) ) );

//------------------Site Identity Ends---------------------

  // Add a custom setting for the primary color
  $wp_customize->add_setting( 'pawprints_blog_primary_color', array(
    'default' => '#996f23',
    'sanitize_callback' => 'sanitize_hex_color',
  ) );

  // Add a custom control for the primary color
  $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'pawprints_blog_primary_color', array(
    'label' => __( 'Primary Color', 'pawprints-blog' ),
    'section' => 'colors',
    'settings' => 'pawprints_blog_primary_color',
  ) ) );

  //-----------------------------------Home Front Page-------------------------------

  $wp_customize->add_panel( 'pawprints_blog_panel', array(
    'title'    => __( 'Front Page Settings', 'pawprints-blog' ),
    'priority' => 6,
  ) );


  //-------------------------------------Banner Image Section--------------

      $wp_customize->add_section( 'pawprints_blog_section_banner', array(
        'title'    => __( 'Home First Section', 'pawprints-blog' ),
        'priority' => 8,
        'panel'    => 'pawprints_blog_panel',
    ) );


  //-----------------Enable Option banner-------------

  $wp_customize->add_setting('pawprints_blog_section_banner',array(
      'default' => 'Enable',
      'sanitize_callback' => 'pawprints_blog_sanitize_choices'
  ));
  $wp_customize->add_control('pawprints_blog_section_banner',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'pawprints-blog'),
        'section' => 'pawprints_blog_section_banner',
        'choices' => array(
            'Enable' => __('Enable', 'pawprints-blog'),
            'Disable' => __('Disable', 'pawprints-blog')
  )));

  $wp_customize->add_setting('pawprints_blog_section_bannerimage_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'pawprints_blog_section_bannerimage_section',array(
    'label' => __('Section Background Image','pawprints-blog'),
    'description' => __('Dimention 1600 * 600','pawprints-blog'),
    'section' => 'pawprints_blog_section_banner',
    'settings' => 'pawprints_blog_section_bannerimage_section'
  )));

    $wp_customize->add_setting('pawprints_blog_section_bannerimage_section_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_section_bannerimage_section_title',array(
      'label' => __('Banner Title','pawprints-blog'),
      'section' => 'pawprints_blog_section_banner',
      'setting' => 'pawprints_blog_section_bannerimage_section_title',
      'type'    => 'text'
    )
  ); 

      $wp_customize->add_setting('pawprints_blog_section_bannerimage_section_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_section_bannerimage_section_text',array(
      'label' => __('Banner Text','pawprints-blog'),
      'section' => 'pawprints_blog_section_banner',
      'setting' => 'pawprints_blog_section_bannerimage_section_text',
      'type'    => 'textarea'
    )
  );

      $wp_customize->add_setting('pawprints_blog_section_bannerimage_section_url_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_section_bannerimage_section_url_title',array(
      'label' => __('Link Title','pawprints-blog'),
      'section' => 'pawprints_blog_section_banner',
      'setting' => 'pawprints_blog_section_bannerimage_section_url_title',
      'type'    => 'text'
    )
  );

      $wp_customize->add_setting('pawprints_blog_section_bannerimage_section_url',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_section_bannerimage_section_url',array(
      'label' => __('Link URL','pawprints-blog'),
      'section' => 'pawprints_blog_section_banner',
      'setting' => 'pawprints_blog_section_bannerimage_section_url',
      'type'    => 'text'
    )
  );


  //--------------------------------------General Settings------------------------------------------

  $wp_customize->add_section( 'pawprints_blog_general', array(
        'title'    => __( 'General Settings', 'pawprints-blog' ),
        'panel'    => 'pawprints_blog_panel',
    ) );



    $wp_customize->add_setting( 'pawprints_blog_header_toggle_switch_control', array(
        'default'   => true,
        'sanitize_callback' => 'sanitize_text_field', // Use a suitable sanitization function based on your needs
        'transport' => 'refresh', // or 'postMessage' for instant preview without page refresh
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'pawprints_blog_header_toggle_switch_control', array(
        'label'    => __( 'Display Read More Button', 'pawprints-blog' ),
        'section'  => 'pawprints_blog_general',
        'settings' => 'pawprints_blog_header_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );

      $wp_customize->add_setting('pawprints_blog_read_more_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_read_more_title',array(
      'label' => __('Read More Button Text','pawprints-blog'),
      'section' => 'pawprints_blog_general',
      'setting' => 'pawprints_blog_read_more_title',
      'type'    => 'text'
    )
  );

      $wp_customize->add_setting('pawprints_blog_read_more_title_url',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_read_more_title_url',array(
      'label' => __('Read More Button URL','pawprints-blog'),
      'section' => 'pawprints_blog_general',
      'setting' => 'pawprints_blog_read_more_title_url',
      'type'    => 'text'
    )
  );


  //----------------------------------Blog category Section---------------


    $wp_customize->add_section( 'pawprints_blog_working_hours_section', array(
        'title'    => __( 'Blog Category Section', 'pawprints-blog' ),
        'priority' => 10,
        'panel'    => 'pawprints_blog_panel',
    ) );

  //-----------------Enable Option Section about-------------

  $wp_customize->add_setting('pawprints_blog_working_hours_section_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'pawprints_blog_sanitize_choices'
  ));
  $wp_customize->add_control('pawprints_blog_working_hours_section_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'pawprints-blog'),
        'section' => 'pawprints_blog_working_hours_section',
        'choices' => array(
            'Enable' => __('Enable', 'pawprints-blog'),
            'Disable' => __('Disable', 'pawprints-blog')
  )));

  $wp_customize->add_setting('pawprints_blog_working_hours_section_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_working_hours_section_title',array(
      'label' => __('Section Title','pawprints-blog'),
      'section' => 'pawprints_blog_working_hours_section',
      'setting' => 'pawprints_blog_working_hours_section_title',
      'type'    => 'text'
    )
  );


    $wp_customize->add_setting('pawprints_blog_working_hours_section_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_working_hours_section_text',array(
      'label' => __('Section Text','pawprints-blog'),
      'section' => 'pawprints_blog_working_hours_section',
      'setting' => 'pawprints_blog_working_hours_section_text',
      'type'    => 'text'
    )
  );


  // ----Category Loop---

    for($i=1;$i<=6;$i++)
  {


    $wp_customize->add_setting('pawprints_blog_section_category_image'.$i,array(
      'default' => '',
      'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(
      new WP_Customize_Image_Control( $wp_customize,'pawprints_blog_section_category_image'.$i,array(
      'label' => __(' Category Image','pawprints-blog').$i,
      'description' => __('Dimension 50 * 50','pawprints-blog'),
      'section' => 'pawprints_blog_working_hours_section',
      'settings' => 'pawprints_blog_section_category_image'.$i
    )));

    $wp_customize->add_setting('pawprints_blog_category_title'.$i,array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('pawprints_blog_category_title'.$i,array(
      'label' => __('Category Title','pawprints-blog').$i,
      'section' => 'pawprints_blog_working_hours_section',
      'setting' => 'pawprints_blog_category_title'.$i,
      'type'    => 'text'
    ));

    $wp_customize->add_setting('pawprints_blog_category_title_url'.$i,array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('pawprints_blog_category_title_url'.$i,array(
      'label' => __('Category URL','pawprints-blog').$i,
      'section' => 'pawprints_blog_working_hours_section',
      'setting' => 'pawprints_blog_category_title_url'.$i,
      'type'    => 'text'
    )); 
}





  //-------------------------Section One (Featured Post)------------------------------------------

  $wp_customize->add_section( 'pawprints_blog_section1', array(
        'title'    => __( 'Latest Post', 'pawprints-blog' ),
        'priority' => 10,
        'panel'    => 'pawprints_blog_panel',
    ) );


  //-----------------Enable Option Section One-------------

  $wp_customize->add_setting('pawprints_blog_section1_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'pawprints_blog_sanitize_choices'
  ));
  $wp_customize->add_control('pawprints_blog_section1_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'pawprints-blog'),
        'section' => 'pawprints_blog_section1',
        'choices' => array(
            'Enable' => __('Enable', 'pawprints-blog'),
            'Disable' => __('Disable', 'pawprints-blog')
  )));



  $wp_customize->add_setting('pawprints_blog_section1_enable_section_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_section1_enable_section_title',array(
      'label' => __('Section Title','pawprints-blog'),
      'section' => 'pawprints_blog_section1',
      'setting' => 'pawprints_blog_section1_enable_section_title',
      'type'    => 'text'
    )
  );


    $wp_customize->add_setting('pawprints_blog_section1_enable_section_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('pawprints_blog_section1_enable_section_text',array(
      'label' => __('Section Text','pawprints-blog'),
      'section' => 'pawprints_blog_section1',
      'setting' => 'pawprints_blog_section1_enable_section_text',
      'type'    => 'text'
    )
  );

  //-----------Category------------

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

  $wp_customize->add_setting('pawprints_blog_section1_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('pawprints_blog_section1_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post','pawprints-blog'),
    'section' => 'pawprints_blog_section1',
    'sanitize_callback' => 'sanitize_text_field',
  ));



    $wp_customize->add_setting('pawprints_blog_section1_category_number_of_posts_setting',array(
    'default' => '3',
    'sanitize_callback' => 'sanitize_text_field'
  ));
  $wp_customize->add_control('pawprints_blog_section1_category_number_of_posts_setting',array(
    'label' => __('Number of Posts','pawprints-blog'),
    'section' => 'pawprints_blog_section1',
    'setting' => 'pawprints_blog_section1_category_number_of_posts_setting',
    'type'    => 'number'
  )); 



  //-------------------------Footer Settings------------------------------


    $wp_customize->add_section( 'pawprints_blog_footer', array(
        'title'    => __( 'Footer Settings', 'pawprints-blog' ),
        'priority' => 10,
        'panel'    => 'pawprints_blog_panel',
    ) );


  // Add a custom setting for the footer text
  $wp_customize->add_setting( 'pawprints_blog_footer_text', array(
    'default' => 'Pawprints Blog Free WordPress Theme',
    'sanitize_callback' => 'sanitize_text_field',
  ) );

  // Add a custom control for the footer text
  $wp_customize->add_control( 'pawprints_blog_footer_text', array(
    'label' => __( 'Footer Text', 'pawprints-blog' ),
    'section' => 'pawprints_blog_footer',
    'type' => 'text',
  ) );


 //-------------------404 Page-----------

  $wp_customize->add_section( 'pawprints_blog_404page', array(
    'title'    => __( '404 Page Settings', 'pawprints-blog' ),
    'priority' => 12,
    'panel'    => 'pawprints_blog_panel',
    ) );


  // Add a custom setting for the footer text
  $wp_customize->add_setting( 'pawprints_blog_404page_title', array(
    'default' => '',
    'sanitize_callback' => 'sanitize_text_field',
  ) );

  // Add a custom control for the footer text
  $wp_customize->add_control( 'pawprints_blog_404page_title', array(
    'label' => __( 'Page Not Found Title', 'pawprints-blog' ),
    'section' => 'pawprints_blog_404page',
    'type' => 'text',
  ) );

  // Add a custom setting for the footer text
  $wp_customize->add_setting( 'pawprints_blog_404page_text', array(
    'default' => '',
    'sanitize_callback' => 'sanitize_text_field',
  ) );

  // Add a custom control for the footer text
  $wp_customize->add_control( 'pawprints_blog_404page_text', array(
    'label' => __( 'Page Not Found Text', 'pawprints-blog' ),
    'section' => 'pawprints_blog_404page',
    'type' => 'text',
  ) );


//--------------------------------------General Settings------------------------------------------

  $wp_customize->add_section( 'pawprints_blog_general', array(
        'title'    => __( 'General Settings', 'pawprints-blog' ),
        'panel'    => 'pawprints_blog_panel',
    ) );

    $wp_customize->add_setting( 'pawprints_blog_post_meta_toggle_switch_control', array(
        'default'   => true,
        'sanitize_callback' => 'sanitize_text_field', // Use a suitable sanitization function based on your needs
        'transport' => 'refresh', // or 'postMessage' for instant preview without page refresh
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'pawprints_blog_post_meta_toggle_switch_control', array(
        'label'    => __( 'Display Time/Author', 'pawprints-blog' ),
        'section'  => 'pawprints_blog_general',
        'settings' => 'pawprints_blog_post_meta_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );


    $wp_customize->add_setting( 'pawprints_blog_post_readmore_toggle_switch_control', array(
        'default'   => true,
        'sanitize_callback' => 'sanitize_text_field', // Use a suitable sanitization function based on your needs
        'transport' => 'refresh', // or 'postMessage' for instant preview without page refresh
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'pawprints_blog_post_readmore_toggle_switch_control', array(
        'label'    => __( 'Display Readmore Link', 'pawprints-blog' ),
        'section'  => 'pawprints_blog_general',
        'settings' => 'pawprints_blog_post_readmore_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );

}
add_action( 'customize_register', 'pawprints_blog_customize_register' );



