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


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

function cat_ecommerce_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';  

    include get_template_directory() . '/inc/customizer-button/upsell-section.php';

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

    $wp_customize->register_section_type( 'Cat_Ecommerce_Customize_Upsell_Section' );

    // Register section.
    $wp_customize->add_section(
        new Cat_Ecommerce_Customize_Upsell_Section(
            $wp_customize,
            'theme_upsell',
            array(
                'title'    => esc_html__( 'CA Beauty Pro', 'cat-ecommerce' ),
                'pro_text' => esc_html__( 'Upgrade To Pro', 'cat-ecommerce' ),
                'pro_url'  => 'https://cawpthemes.com/cat-ecommerce-premium-wordpress-theme/',
                'priority' => 1,
            )
        )
    );
}
add_action( 'customize_register', 'cat_ecommerce_customize_register_btn' );

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

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

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

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

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

    wp_enqueue_script( 'cat-ecommerce-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', 'cat_ecommerce_customizer_control_scripts', 0 );


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


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

function cat_ecommerce_customize_register( $wp_customize ) {



      // Add a custom setting for the Site Identity color
  $wp_customize->add_setting( 'cat_ecommerce_site_identity_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, 'cat_ecommerce_site_identity_color', array(
    'label' => __( 'Site Identity Color', 'cat-ecommerce' ),
    'section' => 'title_tagline',
    'settings' => 'cat_ecommerce_site_identity_color',
  ) ) );


  // Add a custom setting for the Site Identity color
  $wp_customize->add_setting( 'cat_ecommerce_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, 'cat_ecommerce_site_identity_tagline_color', array(
    'label' => __( 'Tagline Color', 'cat-ecommerce' ),
    'section' => 'title_tagline',
    'settings' => 'cat_ecommerce_site_identity_tagline_color',
  ) ) );

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

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

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

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

  $wp_customize->add_panel( 'cat_ecommerce_panel', array(
    'title'    => __( 'Front Page Settings', 'cat-ecommerce' ),
    'priority' => 6,
  ) );


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

      $wp_customize->add_section( 'cat_ecommerce_section_banner', array(
        'title'    => __( 'Banner Section', 'cat-ecommerce' ),
        'priority' => 8,
        'panel'    => 'cat_ecommerce_panel',
    ) );


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

  $wp_customize->add_setting('cat_ecommerce_section_banner',array(
      'default' => 'Enable',
      'sanitize_callback' => 'cat_ecommerce_sanitize_choices'
  ));
  $wp_customize->add_control('cat_ecommerce_section_banner',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'cat-ecommerce'),
        'section' => 'cat_ecommerce_section_banner',
        'choices' => array(
            'Enable' => __('Enable', 'cat-ecommerce'),
            'Disable' => __('Disable', 'cat-ecommerce')
  )));


  $wp_customize->add_setting('cat_ecommerce_section_bannerimage_section_left',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'cat_ecommerce_section_bannerimage_section_left',array(
    'label' => __('Section Left Image','cat-ecommerce'),
    'description' => __('Dimention 700 * 300','cat-ecommerce'),
    'section' => 'cat_ecommerce_section_banner',
    'settings' => 'cat_ecommerce_section_bannerimage_section_left'
  )));

  $wp_customize->add_setting('cat_ecommerce_section_bannerimage_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'cat_ecommerce_section_bannerimage_section',array(
    'label' => __('Section Side Image','cat-ecommerce'),
    'description' => __('Dimention 700 * 750','cat-ecommerce'),
    'section' => 'cat_ecommerce_section_banner',
    'settings' => 'cat_ecommerce_section_bannerimage_section'
  )));

    $wp_customize->add_setting('cat_ecommerce_section_bannerimage_section_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_section_bannerimage_section_title',array(
      'label' => __('Section Title','cat-ecommerce'),
      'section' => 'cat_ecommerce_section_banner',
      'setting' => 'cat_ecommerce_section_bannerimage_section_title',
      'type'    => 'text'
    )
  ); 

      $wp_customize->add_setting('cat_ecommerce_section_bannerimage_section_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_section_bannerimage_section_text',array(
      'label' => __('Section Text','cat-ecommerce'),
      'section' => 'cat_ecommerce_section_banner',
      'setting' => 'cat_ecommerce_section_bannerimage_section_text',
      'type'    => 'textarea'
    )
  );

    $wp_customize->add_setting('cat_ecommerce_banner_btn_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_banner_btn_text',array(
      'label' => __('Button Text','cat-ecommerce'),
      'section' => 'cat_ecommerce_section_banner',
      'setting' => 'cat_ecommerce_banner_btn_text',
      'type'    => 'text'
    )
  );


    $wp_customize->add_setting('cat_ecommerce_banner_btn_text_url',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_banner_btn_text_url',array(
      'label' => __('Button URL','cat-ecommerce'),
      'section' => 'cat_ecommerce_section_banner',
      'setting' => 'cat_ecommerce_banner_btn_text_url',
      'type'    => 'text'
    )
  );

  //----------------------------------Product Section----------------------------



    $wp_customize->add_section( 'cat_ecommerce_product', array(
        'title'    => __( 'Product Section', 'cat-ecommerce' ),
        'priority' => 10,
        'panel'    => 'cat_ecommerce_panel',
    ) );

  //-----------------Enable Option Section Features-------------

  $wp_customize->add_setting('cat_ecommerce_product_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'cat_ecommerce_sanitize_choices'
  ));
  $wp_customize->add_control('cat_ecommerce_product_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'cat-ecommerce'),
        'section' => 'cat_ecommerce_product',
        'choices' => array(
            'Enable' => __('Enable', 'cat-ecommerce'),
            'Disable' => __('Disable', 'cat-ecommerce')
  )));


    $wp_customize->add_setting('cat_ecommerce_product_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_product_title',array(
      'label' => __('Product Section Title','cat-ecommerce'),
      'section' => 'cat_ecommerce_product',
      'setting' => 'cat_ecommerce_product_title',
      'type'    => 'text'
    )
  );

    $wp_customize->add_setting('cat_ecommerce_product_title_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_product_title_text',array(
      'label' => __('Product Section Text','cat-ecommerce'),
      'section' => 'cat_ecommerce_product',
      'setting' => 'cat_ecommerce_product_title_text',
      'type'    => 'text'
    )
  );



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

  $wp_customize->add_section( 'cat_ecommerce_section1', array(
        'title'    => __( 'Latest Post', 'cat-ecommerce' ),
        'priority' => 10,
        'panel'    => 'cat_ecommerce_panel',
    ) );


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

  $wp_customize->add_setting('cat_ecommerce_section1_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'cat_ecommerce_sanitize_choices'
  ));
  $wp_customize->add_control('cat_ecommerce_section1_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'cat-ecommerce'),
        'section' => 'cat_ecommerce_section1',
        'choices' => array(
            'Enable' => __('Enable', 'cat-ecommerce'),
            'Disable' => __('Disable', 'cat-ecommerce')
  )));

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

    $wp_customize->add_setting('cat_ecommerce_section1_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_section1_title',array(
      'label' => __('Section Title','cat-ecommerce'),
      'section' => 'cat_ecommerce_section1',
      'setting' => 'cat_ecommerce_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('cat_ecommerce_section1_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('cat_ecommerce_section1_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post','cat-ecommerce'),
    'section' => 'cat_ecommerce_section1',
    'sanitize_callback' => 'sanitize_text_field',
  ));



    $wp_customize->add_setting('cat_ecommerce_section1_category_number_of_posts_setting',array(
    'default' => '6',
    'sanitize_callback' => 'sanitize_text_field'
  ));
  $wp_customize->add_control('cat_ecommerce_section1_category_number_of_posts_setting',array(
    'label' => __('Number of Posts','cat-ecommerce'),
    'section' => 'cat_ecommerce_section1',
    'setting' => 'cat_ecommerce_section1_category_number_of_posts_setting',
    'type'    => 'number'
  ));


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


  $wp_customize->add_section( 'cat_ecommerce_blogpage_settings', array(
        'title'    => __( 'Blog Page Settings', 'cat-ecommerce' ),
        'priority' => 10,
        'panel'    => 'cat_ecommerce_panel',
    ) );

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

    $wp_customize->add_setting('cat_ecommerce_blogpage_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('cat_ecommerce_blogpage_title',array(
      'label' => __('Blog Page Title','cat-ecommerce'),
      'section' => 'cat_ecommerce_blogpage_settings',
      'setting' => 'cat_ecommerce_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('cat_ecommerce_blogpage_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('cat_ecommerce_blogpage_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post on Blog Page','cat-ecommerce'),
    'section' => 'cat_ecommerce_blogpage_settings',
  ));



    $wp_customize->add_setting('cat_ecommerceblog_page_category_number_of_posts_setting',array(
    'default' => '18',
    'sanitize_callback' => 'sanitize_text_field'
  ));
  $wp_customize->add_control('cat_ecommerceblog_page_category_number_of_posts_setting',array(
    'label' => __('Number of Posts','cat-ecommerce'),
    'section' => 'cat_ecommerce_blogpage_settings',
    'setting' => 'cat_ecommerceblog_page_category_number_of_posts_setting',
    'type'    => 'number'
  )); 



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


    $wp_customize->add_section( 'cat_ecommerce_footer', array(
        'title'    => __( 'Footer Settings', 'cat-ecommerce' ),
        'priority' => 10,
        'panel'    => 'cat_ecommerce_panel',
    ) );


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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'cat_ecommerce_footer_text', array(
    'label' => __( 'Footer Text', 'cat-ecommerce' ),
    'section' => 'cat_ecommerce_footer',
    'type' => 'text',
  ) );


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

  $wp_customize->add_section( 'cat_ecommerce_404page', array(
    'title'    => __( '404 Page Settings', 'cat-ecommerce' ),
    'priority' => 12,
    'panel'    => 'cat_ecommerce_panel',
    ) );


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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'cat_ecommerce_404page_title', array(
    'label' => __( 'Page Not Found Title', 'cat-ecommerce' ),
    'section' => 'cat_ecommerce_404page',
    'type' => 'text',
  ) );

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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'cat_ecommerce_404page_text', array(
    'label' => __( 'Page Not Found Text', 'cat-ecommerce' ),
    'section' => 'cat_ecommerce_404page',
    'type' => 'text',
  ) );


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

  $wp_customize->add_section( 'cat_ecommerce_general', array(
        'title'    => __( 'General Settings', 'cat-ecommerce' ),
        'panel'    => 'cat_ecommerce_panel',
    ) );

    $wp_customize->add_setting( 'cat_ecommerce_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, 'cat_ecommerce_post_meta_toggle_switch_control', array(
        'label'    => __( 'Display Time/Author', 'cat-ecommerce' ),
        'section'  => 'cat_ecommerce_general',
        'settings' => 'cat_ecommerce_post_meta_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );


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




