<?php

function jt_divi_counter_customize_register($wp_customize)
{

    $wp_customize->add_section('et_pagebuilder_jt_divi_counter', array(
        'priority' => 130,
        'capability' => 'edit_theme_options',
        'title' => esc_html__('Counter for Divi', 'Divi'),
    ));

    jt_divi_counter_color_picker(
        $wp_customize,
        'number_text_color',
        'Number Color',
        et_builder_accent_color()
    );

    // Number Font Size
    if (class_exists('ET_Divi_Range_Option')) {
        $wp_customize->add_setting('et_divi[et_pb_jt_counter-number_font_size]', array(
            'default' => '5.0',
            'type' => 'option',
            'capability' => 'edit_theme_options',
            'transport' => 'postMessage',
            'sanitize_callback' => 'absint',
        ));
        $wp_customize->add_control(new ET_Divi_Range_Option($wp_customize, 'et_divi[et_pb_jt_counter-number_font_size]', array(
            'label' => esc_html__('Number Font Size', 'Divi'),
            'section' => 'et_pagebuilder_jt_divi_counter',
            'type' => 'range',
            'input_attrs' => array(
                'min' => 0.1,
                'max' => 20,
                'step' => 0.1,
            ),
        )));
    } else if (class_exists('ET_Range_Control')) {
        $wp_customize->add_setting('et_extra[et_pb_jt_counter-number_font_size]', array(
            'default' => '5.0',
            'type' => 'option',
            'capability' => 'edit_theme_options',
            'transport' => 'postMessage',
            'sanitize_callback' => 'absint',
        ));
        $wp_customize->add_control(new ET_Range_Control($wp_customize, 'et_extra[et_pb_jt_counter-number_font_size]', array(
            'label' => esc_html__('Number Font Size', 'Divi'),
            'section' => 'et_pagebuilder_jt_divi_counter',
            'type' => 'range',
            'input_attrs' => array(
                'min' => 0.1,
                'max' => 20,
                'step' => 0.1,
            ),
        )));
    }
}
add_action('customize_register', 'jt_divi_counter_customize_register');

function jt_divi_counter_color_picker($wp_customize, $slug, $label, $default)
{
    if (class_exists('ET_Divi_Customize_Color_Alpha_Control')) {
        $wp_customize->add_setting('et_divi[et_pb_jt_counter-' . $slug . ']', array(
            'default' => $default,
            'type' => 'option',
            'capability' => 'edit_theme_options',
            'transport' => 'postMessage',
            'sanitize_callback' => 'et_sanitize_alpha_color',
        ));
        $wp_customize->add_control(new ET_Divi_Customize_Color_Alpha_Control($wp_customize, 'et_divi[et_pb_jt_counter-' . $slug . ']', array(
            'label' => $label,
            'section' => 'et_pagebuilder_jt_divi_counter',
            'settings' => 'et_divi[et_pb_jt_counter-' . $slug . ']',
        )));
    } else if (class_exists('ET_Color_Alpha_Control')) {
        $wp_customize->add_setting('et_extra[et_pb_jt_counter-' . $slug . ']', array(
            'default' => $default,
            'type' => 'option',
            'capability' => 'edit_theme_options',
            'transport' => 'postMessage',
            'sanitize_callback' => 'et_sanitize_alpha_color',
        ));
        $wp_customize->add_control(new ET_Color_Alpha_Control($wp_customize, 'et_extra[et_pb_jt_counter-' . $slug . ']', array(
            'label' => $label,
            'section' => 'et_pagebuilder_jt_divi_counter',
            'settings' => 'et_extra[et_pb_jt_counter-' . $slug . ']',
        )));
    }
}
