<?php
/**
 * Counter Settings
 *
 * @package relax_spa
 */
add_action( 'customize_register', 'relax_spa_customize_counter_section' );

function relax_spa_customize_counter_section( $wp_customize ) {

    $wp_customize->add_section( 'relax_spa_counter_sections', array(
        'title'          => esc_html__( 'Counter Section', 'relax-spa' ),
        'panel'          => 'relax_spa_homepage_panel',
    ) );

    $wp_customize->add_setting( 'bs_counter_show_hide_option', array(
        'sanitize_callback'     =>  'relax_spa_sanitize_checkbox',
        'default'               =>  true
    ) );

    $wp_customize->add_control( new Relax_Spa_Toggle_Control( $wp_customize, 'bs_counter_show_hide_option', array(
        'label' => esc_html__( 'Hide / Show','relax-spa' ),
        'section' => 'relax_spa_counter_sections',
        'settings' => 'bs_counter_show_hide_option',
        'type'=> 'relax-spa-toggle',
    ) ) );

    $wp_customize->add_setting( new Relax_Spa_Repeater_Setting( $wp_customize, 'counter_display_option', array(
        'sanitize_callback' => array( 'Relax_Spa_Repeater_Setting', 'sanitize_repeater_setting' ),
    ) ) );

    $wp_customize->add_control( new Relax_Spa_Control_Repeater( $wp_customize, 'counter_display_option', array(
        'section' => 'relax_spa_counter_sections',
        'settings'    => 'counter_display_option',
        'label'   => esc_html__( 'Counter', 'relax-spa' ),
        'row_label' => array(
            'type'  => 'field',
            'value' => esc_html__( 'Counter', 'relax-spa' ),
            'field' => 'counter_text',
        ), 
        'fields' => array(
            'counter_number' => array(
                'type'        => 'text',
                'label'       => esc_html__( 'Enter Number', 'relax-spa' ),
            ),
            'counter_text' => array(
                'type'      => 'text',
                'label'     => esc_html__( 'Enter Text', 'relax-spa' ),
            ),          
        ),
                               
    ) ) );
    
    $wp_customize->selective_refresh->add_partial( 'bs_counter_show_hide_option', array(
        'selector' => '.counter-block > .container', // You can also select a css class
    ) );
}