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


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

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

    $wp_customize->register_section_type( 'logistics_express_Customize_Upsell_Section' );

    // Register section.
    $wp_customize->add_section(
        new logistics_express_Customize_Upsell_Section(
            $wp_customize,
            'theme_upsell',
            array(
                'title'    => esc_html__( 'Logistics Express Pro', 'logistics-express' ),
                'pro_text' => esc_html__( 'Upgrade To Pro', 'logistics-express' ),
                'pro_url'  => 'https://cawpthemes.com/logistics-express-premium-wordpress-theme/',
                'priority' => 1,
            )
        )
    );
}
add_action( 'customize_register', 'logistics_express_customize_register_btn' );

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

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

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

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

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

    wp_enqueue_script( 'logistics-express-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', 'logistics_express_customizer_control_scripts', 0 );


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


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

function logistics_express_customize_register( $wp_customize ) {



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


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

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

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

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

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

  $wp_customize->add_panel( 'logistics_express_panel', array(
    'title'    => __( 'Front Page Settings', 'logistics-express' ),
    'priority' => 6,
  ) );


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

      $wp_customize->add_section( 'logistics_express_section_banner', array(
        'title'    => __( 'Home First Section', 'logistics-express' ),
        'panel'    => 'logistics_express_panel',
    ) );


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

  $wp_customize->add_setting('logistics_express_section_banner',array(
      'default' => 'Enable',
      'sanitize_callback' => 'logistics_express_sanitize_choices'
  ));
  $wp_customize->add_control('logistics_express_section_banner',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'logistics-express'),
        'section' => 'logistics_express_section_banner',
        'choices' => array(
            'Enable' => __('Enable', 'logistics-express'),
            'Disable' => __('Disable', 'logistics-express')
  )));

  $wp_customize->add_setting('logistics_express_section_bannerimage_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'logistics_express_section_bannerimage_section',array(
    'label' => __('Section Side Image','logistics-express'),
    'description' => __('Dimention 500 * 500','logistics-express'),
    'section' => 'logistics_express_section_banner',
    'settings' => 'logistics_express_section_bannerimage_section'
  )));

    $wp_customize->add_setting('logistics_express_section_bannerimage_section_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('logistics_express_section_bannerimage_section_title',array(
      'label' => __('Section Title','logistics-express'),
      'section' => 'logistics_express_section_banner',
      'setting' => 'logistics_express_section_bannerimage_section_title',
      'type'    => 'text'
    )
  ); 

      $wp_customize->add_setting('logistics_express_section_bannerimage_section_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('logistics_express_section_bannerimage_section_text',array(
      'label' => __('Section Text','logistics-express'),
      'section' => 'logistics_express_section_banner',
      'setting' => 'logistics_express_section_bannerimage_section_text',
      'type'    => 'textarea'
    )
  );

    $wp_customize->add_setting('logistics_express_banner_btn_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('logistics_express_banner_btn_text',array(
      'label' => __('Button Text','logistics-express'),
      'section' => 'logistics_express_section_banner',
      'setting' => 'logistics_express_banner_btn_text',
      'type'    => 'text'
    )
  );


    $wp_customize->add_setting('logistics_express_banner_btn_text_url',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('logistics_express_banner_btn_text_url',array(
      'label' => __('Button URL','logistics-express'),
      'section' => 'logistics_express_section_banner',
      'setting' => 'logistics_express_banner_btn_text_url',
      'type'    => 'text'
    )
  );


  //-------------------------Features Section-------------------

    // Add Section
$wp_customize->add_section('logistics_express_section_features', array(
    'title'    => __('Features Section', 'logistics-express'),
    'panel'    => 'logistics_express_panel',
));

// Enable/Disable Option
$wp_customize->add_setting('logistics_express_section_features_enable', array(
    'default'           => 'Enable',
    'sanitize_callback' => 'logistics_express_sanitize_choices',
));
$wp_customize->add_control('logistics_express_section_features_enable', array(
    'type'    => 'radio',
    'label'   => __('Do you want this section?', 'logistics-express'),
    'section' => 'logistics_express_section_features',
    'choices' => array(
        'Enable'  => __('Enable', 'logistics-express'),
        'Disable' => __('Disable', 'logistics-express'),
    ),
));

// Create settings for 3 features
for ($i = 1; $i <= 3; $i++) {

    // Feature Title
    $wp_customize->add_setting("logistics_express_feature_title_$i", array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control("logistics_express_feature_title_$i", array(
        'label'   => sprintf(__('Feature Title %d', 'logistics-express'), $i),
        'section' => 'logistics_express_section_features',
        'type'    => 'text',
    ));

    // Feature Description
    $wp_customize->add_setting("logistics_express_feature_text_$i", array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field',
    ));
    $wp_customize->add_control("logistics_express_feature_text_$i", array(
        'label'   => sprintf(__('Feature Description %d', 'logistics-express'), $i),
        'section' => 'logistics_express_section_features',
        'type'    => 'textarea',
    ));
}


// Add About Section to Customizer
 // Add About Section
    $wp_customize->add_section('logistics_express_section_about', array(
        'title'    => __('About Section', 'logistics-express'),
        'panel'    => 'logistics_express_panel',
    ));

    // Title
    $wp_customize->add_setting('logistics_express_about_title', array(
        'default'           => __('Cost-Effective Logistics Services', 'logistics-express'),
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('logistics_express_about_title', array(
        'label'   => __('Section Title', 'logistics-express'),
        'section' => 'logistics_express_section_about',
        'type'    => 'text',
    ));

    // Description
    $wp_customize->add_setting('logistics_express_about_desc', array(
        'default'           => __('Aliquam class euismod lobortis condimentum elementum...', 'logistics-express'),
        'sanitize_callback' => 'sanitize_textarea_field',
    ));
    $wp_customize->add_control('logistics_express_about_desc', array(
        'label'   => __('Section Description', 'logistics-express'),
        'section' => 'logistics_express_section_about',
        'type'    => 'textarea',
    ));

    // Image
    $wp_customize->add_setting('logistics_express_about_image', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(
        new WP_Customize_Image_Control(
            $wp_customize,
            'logistics_express_about_image',
            array(
                'label'    => __('About Section Image', 'logistics-express'),
                'section'  => 'logistics_express_section_about',
                'settings' => 'logistics_express_about_image',
            )
        )
    );


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

  $wp_customize->add_section( 'logistics_express_section1', array(
        'title'    => __( 'Latest Post', 'logistics-express' ),
        'panel'    => 'logistics_express_panel',
    ) );


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

  $wp_customize->add_setting('logistics_express_section1_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'logistics_express_sanitize_choices'
  ));
  $wp_customize->add_control('logistics_express_section1_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'logistics-express'),
        'section' => 'logistics_express_section1',
        'choices' => array(
            'Enable' => __('Enable', 'logistics-express'),
            'Disable' => __('Disable', 'logistics-express')
  )));

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

    $wp_customize->add_setting('logistics_express_section1_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('logistics_express_section1_title',array(
      'label' => __('Section Title','logistics-express'),
      'section' => 'logistics_express_section1',
      'setting' => 'logistics_express_section1_title',
      'type'    => 'text'
    )
  ); 

      $wp_customize->add_setting('logistics_express_section1_subtitle',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('logistics_express_section1_subtitle',array(
      'label' => __('Section Sub Title','logistics-express'),
      'section' => 'logistics_express_section1',
      'setting' => 'logistics_express_section1_subtitle',
      '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('logistics_express_section1_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('logistics_express_section1_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post','logistics-express'),
    'section' => 'logistics_express_section1',
    'sanitize_callback' => 'sanitize_text_field',
  ));



    $wp_customize->add_setting('logistics_express_section1_category_number_of_posts_setting',array(
    'default' => '6',
    'sanitize_callback' => 'sanitize_text_field'
  ));
  $wp_customize->add_control('logistics_express_section1_category_number_of_posts_setting',array(
    'label' => __('Number of Posts','logistics-express'),
    'section' => 'logistics_express_section1',
    'setting' => 'logistics_express_section1_category_number_of_posts_setting',
    'type'    => 'number'
  ));


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


  $wp_customize->add_section( 'logistics_express_blogpage_settings', array(
        'title'    => __( 'Blog Page Settings', 'logistics-express' ),
        'panel'    => 'logistics_express_panel',
    ) );

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

    $wp_customize->add_setting('logistics_express_blogpage_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('logistics_express_blogpage_title',array(
      'label' => __('Blog Page Title','logistics-express'),
      'section' => 'logistics_express_blogpage_settings',
      'setting' => 'logistics_express_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('logistics_express_blogpage_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('logistics_express_blogpage_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post on Blog Page','logistics-express'),
    'section' => 'logistics_express_blogpage_settings',
    'sanitize_callback' => 'sanitize_text_field',
  ));

    $wp_customize->add_setting('logistics_expressblog_page_category_number_of_posts_setting',array(
    'default' => '18',
    'sanitize_callback' => 'sanitize_text_field'
  ));
  $wp_customize->add_control('logistics_expressblog_page_category_number_of_posts_setting',array(
    'label' => __('Number of Posts','logistics-express'),
    'section' => 'logistics_express_blogpage_settings',
    'setting' => 'logistics_expressblog_page_category_number_of_posts_setting',
    'type'    => 'number'
  )); 



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


    $wp_customize->add_section( 'logistics_express_footer', array(
        'title'    => __( 'Footer Settings', 'logistics-express' ),
        'panel'    => 'logistics_express_panel',
    ) );


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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'logistics_express_footer_text', array(
    'label' => __( 'Footer Text', 'logistics-express' ),
    'section' => 'logistics_express_footer',
    'type' => 'text',
  ) );


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

  $wp_customize->add_section( 'logistics_express_404page', array(
    'title'    => __( '404 Page Settings', 'logistics-express' ),
    'panel'    => 'logistics_express_panel',
    ) );


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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'logistics_express_404page_title', array(
    'label' => __( 'Page Not Found Title', 'logistics-express' ),
    'section' => 'logistics_express_404page',
    'type' => 'text',
  ) );

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

  // Add a custom control for the footer text
  $wp_customize->add_control( 'logistics_express_404page_text', array(
    'label' => __( 'Page Not Found Text', 'logistics-express' ),
    'section' => 'logistics_express_404page',
    'type' => 'text',
  ) );

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

  $wp_customize->add_section( 'logistics_express_general', array(
        'title'    => __( 'General Settings', 'logistics-express' ),
        'panel'    => 'logistics_express_panel',
    ) );

    $wp_customize->add_setting( 'logistics_express_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, 'logistics_express_post_meta_toggle_switch_control', array(
        'label'    => __( 'Display Time/Author', 'logistics-express' ),
        'section'  => 'logistics_express_general',
        'settings' => 'logistics_express_post_meta_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );

    $wp_customize->add_setting( 'logistics_express_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, 'logistics_express_post_meta_toggle_switch_control', array(
        'label'    => __( 'Display Read More Link', 'logistics-express' ),
        'section'  => 'logistics_express_general',
        'settings' => 'logistics_express_post_meta_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );


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



