<?php

/**
 * Service Section
 *
 * @package moving_truck_rental
 */

$wp_customize->add_section(
	'moving_truck_rental_product_section',
	array(
		'panel'    => 'moving_truck_rental_front_page_options',
		'title'    => esc_html__( 'Services Section', 'moving-truck-rental' ),
		'priority' => 10,
	)
);

// Service Section - Enable Section.
$wp_customize->add_setting(
	'moving_truck_rental_enable_service_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'moving_truck_rental_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Moving_Truck_Rental_Toggle_Switch_Custom_Control(
		$wp_customize,
		'moving_truck_rental_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Services Section', 'moving-truck-rental' ),
			'section'  => 'moving_truck_rental_product_section',
			'settings' => 'moving_truck_rental_enable_service_section',
		)
	)
);

if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'moving_truck_rental_enable_service_section',
		array(
			'selector' => '#moving_truck_rental_service_section .section-link',
			'settings' => 'moving_truck_rental_enable_service_section',
		)
	);
}

// Service Section - Button Label.
$wp_customize->add_setting(
	'moving_truck_rental_trending_product_heading',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'moving_truck_rental_trending_product_heading',
	array(
		'label'           => esc_html__( 'Heading', 'moving-truck-rental' ),
		'section'         => 'moving_truck_rental_product_section',
		'settings'        => 'moving_truck_rental_trending_product_heading',
		'type'            => 'text',
		'active_callback' => 'moving_truck_rental_is_service_section_enabled',
	)
);

$wp_customize->add_setting(
	'moving_truck_rental_services_number',
	array(
	    'default'=> '',
	    'sanitize_callback' => 'sanitize_text_field'
));
$wp_customize->add_control(
	'moving_truck_rental_services_number',
	array(
	    'label' => esc_html__('No of Tabs to show','moving-truck-rental'),
	    'description' => esc_html__('Add Tabs Then Refresh this page to show Fields','moving-truck-rental'),
	    'section'=> 'moving_truck_rental_product_section',
	    'type' => 'number',
	    'input_attrs' => array(
	    'step'  => 1,
			'min'  => 0,
			'max'  => 7,
	    ),
	    'active_callback' => 'moving_truck_rental_is_service_section_enabled',
	)
);

$moving_truck_rental_featured_post = get_theme_mod('moving_truck_rental_services_number','');
for ( $moving_truck_rental_j = 1; $moving_truck_rental_j <= $moving_truck_rental_featured_post; $moving_truck_rental_j++ ) {

    $wp_customize->add_setting(
    	'moving_truck_rental_services_text'.$moving_truck_rental_j,
    	array(
	        'default'=> '',
	        'sanitize_callback' => 'sanitize_text_field'
    	)
    );
    $wp_customize->add_control(
    	'moving_truck_rental_services_text'.$moving_truck_rental_j,
    	array(
	        'label' => esc_html__('Tab ','moving-truck-rental').$moving_truck_rental_j,
	        'section'=> 'moving_truck_rental_product_section',
	        'type'=> 'text',
	        'active_callback' => 'moving_truck_rental_is_service_section_enabled',
    	)
    );

	$moving_truck_rental_args = array(
		'type'                     => 'post', // Changed from 'product' to 'post'
		'child_of'                 => 0,
		'parent'                   => '',
		'orderby'                  => 'term_group',
		'order'                    => 'ASC',
		'hide_empty'               => false,
		'hierarchical'             => 1,
		'number'                   => '',
		'taxonomy'                 => 'category', // Changed from 'product_cat' to 'category'
		'pad_counts'               => false
	);
	$moving_truck_rental_categories = get_categories($moving_truck_rental_args);
	$moving_truck_rental_cat_posts = array();
	$moving_truck_rental_m = 0;
	$moving_truck_rental_cat_posts[] = 'Select';

	foreach($moving_truck_rental_categories as $moving_truck_rental_category){
		if($moving_truck_rental_m == 0){
			$moving_truck_rental_default = $moving_truck_rental_category->slug;
			$moving_truck_rental_m++;
		}
		$moving_truck_rental_cat_posts[$moving_truck_rental_category->slug] = $moving_truck_rental_category->name;
	}

	$wp_customize->add_setting('moving_truck_rental_trending_post_category'.$moving_truck_rental_j, array(
		'default'	=> 'select',
		'sanitize_callback' => 'moving_truck_rental_sanitize_select',
	));

	$wp_customize->add_control('moving_truck_rental_trending_post_category'.$moving_truck_rental_j, array(
		'type'    => 'select',
		'choices' => $moving_truck_rental_cat_posts,
		'label'   => __('Select category to display posts ','moving-truck-rental'),
		'section' => 'moving_truck_rental_product_section', // Adjust the section as needed
		'active_callback' => 'moving_truck_rental_is_service_section_enabled',
	));
}