<?php
/**
 * Add custom settings and controls to the WordPress Customizer
 */


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

function anime_verse_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' => 'anime_verse_customize_partial_blogname',
        ) );
        $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
            'selector'        => '.site-description',
            'render_callback' => 'anime_verse_customize_partial_blogdescription',
        ) );
    }

    $wp_customize->register_section_type( 'Anime_Verse_Customize_Upsell_Section' );

    // Register section.
    $wp_customize->add_section(
        new Anime_Verse_Customize_Upsell_Section(
            $wp_customize,
            'theme_upsell',
            array(
                'title'    => esc_html__( 'Anime Verse Pro', 'anime-verse' ),
                'pro_text' => esc_html__( 'Upgrade To Pro', 'anime-verse' ),
                'pro_url'  => 'https://cawpthemes.com/anime-verse-premium-wordpress-theme/',
                'priority' => 1,
            )
        )
    );
}
add_action( 'customize_register', 'anime_verse_customize_register_btn' );

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

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

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

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

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

    wp_enqueue_script( 'anime-verse-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', 'anime_verse_customizer_control_scripts', 0 );


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


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

function anime_verse_customize_register( $wp_customize ) {


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

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


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

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

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


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

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

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

  $wp_customize->add_panel( 'anime_verse_panel', array(
    'title'    => __( 'Front Page Settings', 'anime-verse' ),
    'priority' => 6,
  ) );


  //--------Trending Post------------------------------------------

  $wp_customize->add_section( 'anime_verse_section_trend', array(
        'title'    => __( 'Trending Post (Section One)', 'anime-verse' ),
        'priority' => 10,
        'panel'    => 'anime_verse_panel',
    ) );


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

  $wp_customize->add_setting('anime_verse_section_trend_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'anime_verse_sanitize_choices'
  ));
  $wp_customize->add_control('anime_verse_section_trend_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'anime-verse'),
        'section' => 'anime_verse_section_trend',
        'choices' => array(
            'Enable' => __('Enable', 'anime-verse'),
            'Disable' => __('Disable', 'anime-verse')
  )));

  //-----------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('anime_verse_section_trend_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('anime_verse_section_trend_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post','anime-verse'),
    'section' => 'anime_verse_section_trend',
    'sanitize_callback' => 'sanitize_text_field',
  )); 



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

  $wp_customize->add_section( 'anime_verse_section1', array(
        'title'    => __( 'Featured Post (Section Two)', 'anime-verse' ),
        'priority' => 10,
        'panel'    => 'anime_verse_panel',
    ) );


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

  $wp_customize->add_setting('anime_verse_section1_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'anime_verse_sanitize_choices'
  ));
  $wp_customize->add_control('anime_verse_section1_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'anime-verse'),
        'section' => 'anime_verse_section1',
        'choices' => array(
            'Enable' => __('Enable', 'anime-verse'),
            'Disable' => __('Disable', 'anime-verse')
  )));

    //--------------Section One Title-----------------------

    $wp_customize->add_setting('anime_verse_section1_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('anime_verse_section1_title',array(
      'label' => __('Section Title','anime-verse'),
      'section' => 'anime_verse_section1',
      'setting' => 'anime_verse_section1_title',
      '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('anime_verse_section1_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('anime_verse_section1_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post','anime-verse'),
    'section' => 'anime_verse_section1',
    'sanitize_callback' => 'sanitize_text_field',
  )); 


//------------------------Blog Page Settings--------------------------


  $wp_customize->add_section( 'anime_verse_blogpage_settings', array(
        'title'    => __( 'Blog Page Settings', 'anime-verse' ),
        'priority' => 10,
        'panel'    => 'anime_verse_panel',
    ) );

    //--------------Section One Title-----------------------

    $wp_customize->add_setting('anime_verse_blogpage_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('anime_verse_blogpage_title',array(
      'label' => __('Blog Page Title','anime-verse'),
      'section' => 'anime_verse_blogpage_settings',
      'setting' => 'anime_verse_blogpage_title',
      '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('anime_verse_blogpage_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('anime_verse_blogpage_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post on Blog Page','anime-verse'),
    'section' => 'anime_verse_blogpage_settings',
    'sanitize_callback' => 'sanitize_text_field',
  ));



    $wp_customize->add_setting('anime_verseblog_page_category_number_of_posts_setting',array(
    'default' => '18',
    'sanitize_callback' => 'sanitize_text_field'
  ));
  $wp_customize->add_control('anime_verseblog_page_category_number_of_posts_setting',array(
    'label' => __('Number of Posts','anime-verse'),
    'section' => 'anime_verse_blogpage_settings',
    'setting' => 'anime_verseblog_page_category_number_of_posts_setting',
    'type'    => 'number'
  )); 




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


    $wp_customize->add_section( 'anime_verse_footer', array(
        'title'    => __( 'Footer Settings', 'anime-verse' ),
        'priority' => 10,
        'panel'    => 'anime_verse_panel',
    ) );


  // Add a custom setting for the footer text
  $wp_customize->add_setting( 'anime_verse_footer_text', array(
    'default' => __('Anime Verse WordPress Theme', 'anime-verse'),
    'sanitize_callback' => 'sanitize_text_field',
  ) );

  // Add a custom control for the footer text
  $wp_customize->add_control( 'anime_verse_footer_text', array(
    'label' => __( 'Footer Text', 'anime-verse' ),
    'section' => 'anime_verse_footer',
    'type' => 'text',
  ) );



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

  $wp_customize->add_section( 'anime_verse_404page', array(
    'title'    => __( '404 Page Settings', 'anime-verse' ),
    'priority' => 12,
    'panel'    => 'anime_verse_panel',
    ) );


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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'anime_verse_404page_title', array(
    'label' => __( 'Page Not Found Title', 'anime-verse' ),
    'section' => 'anime_verse_404page',
    'type' => 'text',
  ) );

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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'anime_verse_404page_text', array(
    'label' => __( 'Page Not Found Text', 'anime-verse' ),
    'section' => 'anime_verse_404page',
    'type' => 'text',
  ) );

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

  $wp_customize->add_section( 'anime_verse_general', array(
        'title'    => __( 'General Settings', 'anime-verse' ),
        'panel'    => 'anime_verse_panel',
    ) );

    $wp_customize->add_setting( 'anime_verse_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, 'anime_verse_post_meta_toggle_switch_control', array(
        'label'    => __( 'Display Time/Author', 'anime-verse' ),
        'section'  => 'anime_verse_general',
        'settings' => 'anime_verse_post_meta_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );

    $wp_customize->add_setting( 'anime_verse_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, 'anime_verse_post_readmore_toggle_switch_control', array(
        'label'    => __( 'Display Readmore Link', 'anime-verse' ),
        'section'  => 'anime_verse_general',
        'settings' => 'anime_verse_post_readmore_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );



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


