<?php
/**
 * Theme Customizer Controls
 *
 * @package Legacy Medical Appointment
 */

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

    $wp_customize->add_section(
        'legacy_medical_appointment_home_blog_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'title'         => esc_html__( 'Latest News Settings', 'legacy-medical-appointment' )
        )
    );

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

    $wp_customize->add_control( 
        new Legacy_Medical_Appointment_Title_Info_Control( $wp_customize, 'legacy_medical_appointment_label_latest_news_settings_title', 
        array(
            'label'       => esc_html__( 'Latest News Settings', 'legacy-medical-appointment' ),
            'section'     => 'legacy_medical_appointment_home_blog_settings',
            'type'        => 'legacy-medical-appointment-title',
            'settings'    => 'legacy_medical_appointment_label_latest_news_settings_title',
        ) 
    ));

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

    $wp_customize->add_control(
        'legacy_medical_appointment_latest_news_small_heading',
        array(
            'label'           => sprintf( esc_html__( 'Small Heading', 'legacy-medical-appointment' ), ),
            'section'         => 'legacy_medical_appointment_home_blog_settings',
            'settings'        => 'legacy_medical_appointment_latest_news_small_heading' ,
            'type'            => 'text',
        )
    );

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

    $wp_customize->add_control(
        'legacy_medical_appointment_latest_news_main_heading',
        array(
            'label'           => sprintf( esc_html__( 'Main Heading', 'legacy-medical-appointment' ), ),
            'section'         => 'legacy_medical_appointment_home_blog_settings',
            'settings'        => 'legacy_medical_appointment_latest_news_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_medical_appointment_selected_category',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_medical_appointment_selected_category',
        array(
            'label'    => esc_html__( 'Select Post Category', 'legacy-medical-appointment' ),
            'section'  => 'legacy_medical_appointment_home_blog_settings',
            'settings' => 'legacy_medical_appointment_selected_category',
            'type'     => 'select',
            'choices'  => $cat_post,
        )
    );

   $wp_customize->add_setting( 'legacy_medical_appointment_latest_news_number', array(
        'default'           => 3, 
        'sanitize_callback' => 'absint',
    ));

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

add_action( 'customize_register', 'legacy_medical_appointment_customizer_home_blog_register' );