<?php
/**
 * Theme Customizer Controls
 *
 * @package Legacy Wellness Coach
 */

if ( ! function_exists( 'legacy_wellness_coach_customizer_home_destination_register' ) ) :
function legacy_wellness_coach_customizer_home_destination_register( $wp_customize ) {

    $wp_customize->add_section(
        'legacy_wellness_coach_home_destination_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'title'         => esc_html__( 'Programs Settings', 'legacy-wellness-coach' )
        )
    );

    // Title label
    $wp_customize->add_setting( 
        'legacy_wellness_coach_label_product_settings_title', 
        array(
            'sanitize_callback' => 'legacy_wellness_coach_sanitize_title',
        ) 
    );

    $wp_customize->add_control( 
        new Legacy_Wellness_Coach_Title_Info_Control( $wp_customize, 'legacy_wellness_coach_label_product_settings_title', 
        array(
            'label'       => esc_html__( 'Programs Settings', 'legacy-wellness-coach' ),
            'section'     => 'legacy_wellness_coach_home_destination_settings',
            'type'        => 'legacy-wellness-coach-title',
            'settings'    => 'legacy_wellness_coach_label_product_settings_title',
        ) 
    ));

    $wp_customize->add_setting(
        'legacy_wellness_coach_destination_small_heading',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_destination_small_heading',
        array(
            'label'           => sprintf( esc_html__( 'Small Heading', 'legacy-wellness-coach' ), ),
            'section'         => 'legacy_wellness_coach_home_destination_settings',
            'settings'        => 'legacy_wellness_coach_destination_small_heading' ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
        'legacy_wellness_coach_destination_main_heading',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_destination_main_heading',
        array(
            'label'           => sprintf( esc_html__( 'Main Heading', 'legacy-wellness-coach' ), ),
            'section'         => 'legacy_wellness_coach_home_destination_settings',
            'settings'        => 'legacy_wellness_coach_destination_main_heading' ,
            'type'            => 'text',
        )
    );
    
    $categories = get_categories();
    $cat_post = array();
    $cat_post[]= 'select';
    $i = 0; 
    foreach($categories as $category){
        if($i==0){
            $default = $category->slug;
            $i++;
        }
        $cat_post[$category->slug] = $category->name;
    }

    $wp_customize->add_setting(
        'legacy_wellness_coach_destination_category',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_destination_category',
        array(
            'label'    => esc_html__( 'Select Post Category', 'legacy-wellness-coach' ),
            'section'  => 'legacy_wellness_coach_home_destination_settings',
            'settings' => 'legacy_wellness_coach_destination_category',
            'type'     => 'select',
            'choices'  => $cat_post,
        )
    );

   $wp_customize->add_setting( 'legacy_wellness_coach_destination_topics_number', array(
        'default'           => 0, 
        'sanitize_callback' => 'absint',
    ));

    // Add control for number of products
    $wp_customize->add_control( 'legacy_wellness_coach_destination_topics_number', array(
        'label'       => __( 'Number of Post to Display', 'legacy-wellness-coach' ),
        'section'     => 'legacy_wellness_coach_home_destination_settings', 
        'type'        => 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 8,
        ),
    ));
}
endif;

add_action( 'customize_register', 'legacy_wellness_coach_customizer_home_destination_register' );