<?php
// Popular Posts Options.
$wp_customize->add_section(
    'home_page_popular_post_options',
    array(
        'title' => __('Popular Options', 'newsmachine'),
        'panel' => 'header_options_panel',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[enable_popular_posts]',
    array(
        'default' => $newsmachine_default['enable_popular_posts'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_posts]',
    array(
        'label' => __('Enable Popular Section', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
    )
);

$wp_customize->add_setting(
    'newsmachine_options[enable_popular_only_on_frontpage]',
    array(
        'default' => $newsmachine_default['enable_popular_only_on_frontpage'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_only_on_frontpage]',
    array(
        'label' => __('Display only on the Homepage', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
    )
);


$wp_customize->add_setting(
    'newsmachine_options[enable_popular_label]',
    array(
        'default'           => $newsmachine_default['enable_popular_label'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_label]',
    array(
        'label'           => __( 'Enable Popular Label', 'newsmachine' ),
        'section'     => 'home_page_popular_post_options',
        'type'        => 'checkbox',
    )
);

// Popular Label Text.
$wp_customize->add_setting(
    'newsmachine_options[popular_label_text]',
    array(
        'default'           => $newsmachine_default['popular_label_text'],
        'sanitize_callback' => 'sanitize_text_field',
    )
);
$wp_customize->add_control(
    'newsmachine_options[popular_label_text]',
    array(
        'label'           => __( 'Popular Label', 'newsmachine' ),
        'description'     => __( 'Leave blank to use the default text "Latest".', 'newsmachine' ),
        'section'         => 'home_page_popular_post_options',
        'type'            => 'text',
    )
);


// Popular Posts Category.
$wp_customize->add_setting(
    'newsmachine_options[popular_post_cat]',
    array(
        'default' => $newsmachine_default['popular_post_cat'],
        'sanitize_callback' => 'absint',
    )
);
$wp_customize->add_control(
    new NewsMachine_Dropdown_Taxonomies_Control(
        $wp_customize,
        'newsmachine_options[popular_post_cat]',
        array(
            'label' => __('Choose Category', 'newsmachine'),
            'section' => 'home_page_popular_post_options',
        )
    )
);
// No of posts.
$wp_customize->add_setting(
    'newsmachine_options[no_of_popular_posts]',
    array(
        'default' => $newsmachine_default['no_of_popular_posts'],
        'sanitize_callback' => 'absint',
    )
);
$wp_customize->add_control(
    'newsmachine_options[no_of_popular_posts]',
    array(
        'label' => __('Number of Posts', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'number',
    )
);

// No of posts offset.
$wp_customize->add_setting(
    'newsmachine_options[popular_posts_number_of_post_offsets]',
    array(
        'default' => $newsmachine_default['popular_posts_number_of_post_offsets'],
        'sanitize_callback' => 'absint',
    )
);
$wp_customize->add_control(
    'newsmachine_options[popular_posts_number_of_post_offsets]',
    array(
        'label' => __('Post Offset Number', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'number',
    )
);


// Posts Orderby.
$wp_customize->add_setting(
    'newsmachine_options[popular_post_orderby]',
    array(
        'default' => $newsmachine_default['popular_post_orderby'],
        'sanitize_callback' => 'newsmachine_sanitize_select',
    )
);
$wp_customize->add_control(
    'newsmachine_options[popular_post_orderby]',
    array(
        'label' => __('Orderby', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'select',
        'choices' => array(
            'date' => __('Date', 'newsmachine'),
            'id' => __('ID', 'newsmachine'),
            'title' => __('Title', 'newsmachine'),
            'rand' => __('Random', 'newsmachine'),
        ),
    )
);
// Posts Order.
$wp_customize->add_setting(
    'newsmachine_options[popular_post_order]',
    array(
        'default' => $newsmachine_default['popular_post_order'],
        'sanitize_callback' => 'newsmachine_sanitize_select',
    )
);
$wp_customize->add_control(
    'newsmachine_options[popular_post_order]',
    array(
        'label' => __('Order', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'select',
        'choices' => array(
            'asc' => __('ASC', 'newsmachine'),
            'desc' => __('DESC', 'newsmachine'),
        ),
    )
);
$wp_customize->add_setting(
    'newsmachine_options[enable_popular_post_author_meta]',
    array(
        'default' => $newsmachine_default['enable_popular_post_author_meta'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_post_author_meta]',
    array(
        'label' => esc_html__('Display Author Meta', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[select_popular_post_author_meta]',
    array(
        'default' => $newsmachine_default['select_popular_post_author_meta'],
        'sanitize_callback' => 'newsmachine_sanitize_select',
    )
);
$wp_customize->add_control(
    'newsmachine_options[select_popular_post_author_meta]',
    array(
        'label' => esc_html__('Select Author Meta', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'select',
        'choices' => newsmachine_author_meta(),
    )
);
$wp_customize->add_setting(
    'newsmachine_options[popular_post_author_meta_title]',
    array(
        'default' => $newsmachine_default['popular_post_author_meta_title'],
        'sanitize_callback' => 'sanitize_text_field',
    )
);
$wp_customize->add_control(
    'newsmachine_options[popular_post_author_meta_title]',
    array(
        'label' => __('Author Meta Text', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'text',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[enable_popular_post_date_meta]',
    array(
        'default' => $newsmachine_default['enable_popular_post_date_meta'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_post_date_meta]',
    array(
        'label' => esc_html__('Display Published Date', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[select_popular_post_date]',
    array(
        'default' => $newsmachine_default['select_popular_post_date'],
        'sanitize_callback' => 'newsmachine_sanitize_select',
    )
);
$wp_customize->add_control(
    'newsmachine_options[select_popular_post_date]',
    array(
        'label' => esc_html__('Select Date Meta', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'select',
        'choices' => newsmachine_date_meta(),
    )
);
$wp_customize->add_setting(
    'newsmachine_options[select_popular_post_date_meta_title]',
    array(
        'default' => $newsmachine_default['select_popular_post_date_meta_title'],
        'sanitize_callback' => 'sanitize_text_field',
    )
);
$wp_customize->add_control(
    'newsmachine_options[select_popular_post_date_meta_title]',
    array(
        'label' => __('Date Meta Text', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'text',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[select_popular_post_date_format]',
    array(
        'default' => $newsmachine_default['select_popular_post_date_format'],
        'sanitize_callback' => 'newsmachine_sanitize_select',
    )
);
$wp_customize->add_control(
    'newsmachine_options[select_popular_post_date_format]',
    array(
        'label' => esc_html__('Select Date Format', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'select',
        'choices' => newsmachine_get_date_formats(),
    )
);

$wp_customize->add_setting(
    'newsmachine_options[enable_popular_category_meta]',
    array(
        'default' => $newsmachine_default['enable_popular_category_meta'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_category_meta]',
    array(
        'label' => esc_html__('Enable Category Meta', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[select_popular_number_of_category]',
    array(
        'default' => $newsmachine_default['select_popular_number_of_category'],
        'sanitize_callback' => 'absint',
    )
);
$wp_customize->add_control(
    'newsmachine_options[select_popular_number_of_category]',
    array(
        'label' => __('Number of Category', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'number',
    )
);

$wp_customize->add_setting(
    'newsmachine_options[popular_post_offset_number]',
    array(
        'default' => $newsmachine_default['popular_post_offset_number'],
        'sanitize_callback' => 'absint',
    )
);
$wp_customize->add_control(
    'newsmachine_options[popular_post_offset_number]',
    array(
        'label' => __('Post Offset', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'number',
    )
);

$wp_customize->add_setting(
    'newsmachine_options[popular_category_label]',
    array(
        'default' => $newsmachine_default['popular_category_label'],
        'sanitize_callback' => 'sanitize_text_field',
    )
);
$wp_customize->add_control(
    'newsmachine_options[popular_category_label]',
    array(
        'label' => __('Category Label', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'text',
    )
);

$wp_customize->add_setting(
    'newsmachine_options[select_popular_category_color]',
    array(
        'default' => $newsmachine_default['select_popular_category_color'],
        'sanitize_callback' => 'newsmachine_sanitize_select',
    )
);
$wp_customize->add_control(
    'newsmachine_options[select_popular_category_color]',
    array(
        'label' => esc_html__('Select Category Color', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'select',
        'choices' => newsmachine_category_color(),
    )
);

// Enable  Autoplay.
$wp_customize->add_setting(
    'newsmachine_options[enable_popular_post_autoplay]',
    array(
        'default' => $newsmachine_default['enable_popular_post_autoplay'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_post_autoplay]',
    array(
        'label' => __('Enable Autoplay', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
        'active_callback' => 'newsmachine_is_popular_post_enabled',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[enable_popular_post_arrows]',
    array(
        'default' => $newsmachine_default['enable_popular_post_arrows'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_post_arrows]',
    array(
        'label' => __('Enable Arrows', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
        'active_callback' => 'newsmachine_is_popular_post_enabled',
    )
);
$wp_customize->add_setting(
    'newsmachine_options[enable_popular_post_dots]',
    array(
        'default' => $newsmachine_default['enable_popular_post_dots'],
        'sanitize_callback' => 'newsmachine_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'newsmachine_options[enable_popular_post_dots]',
    array(
        'label' => __('Enable Dots', 'newsmachine'),
        'section' => 'home_page_popular_post_options',
        'type' => 'checkbox',
        'active_callback' => 'newsmachine_is_popular_post_enabled',
    )
);
