<?php

/**
 * Rearrange Sections
 *
 * @package bootstrap_coach
 */
add_action( 'customize_register', 'bootstrap_coach_sort_homepage_sections' );
function bootstrap_coach_sort_homepage_sections(  $wp_customize  ) {
    $wp_customize->add_section( 'bootstrap_coach_sort_homepage_sections', array(
        'title'    => esc_html__( 'Rearrange Home Sections', 'bootstrap-coach' ),
        'panel'    => '',
        'priority' => 13,
    ) );
    if ( class_exists( 'The_Bootstrap_Themes_Companion' ) ) {
        $default = array(
            'info',
            'about',
            'counter',
            'teams',
            'testimonial',
            'price',
            'newsletter',
            'blogs'
        );
        $choices = array(
            'info'        => esc_html__( 'CTA Section', 'bootstrap-coach' ),
            'about'       => esc_html__( 'About Section', 'bootstrap-coach' ),
            'counter'     => esc_html__( 'Counter Section', 'bootstrap-coach' ),
            'teams'       => esc_html__( 'Teams Section', 'bootstrap-coach' ),
            'testimonial' => esc_html__( 'Testimonial Section', 'bootstrap-coach' ),
            'price'       => esc_html__( 'Price Section', 'bootstrap-coach' ),
            'newsletter'  => esc_html__( 'Newsletter Section', 'bootstrap-coach' ),
            'blogs'       => esc_html__( 'Blog Section', 'bootstrap-coach' ),
        );
    } else {
        $default = array(
            'info',
            'about',
            'counter',
            'newsletter',
            'blogs'
        );
        $choices = array(
            'info'       => esc_html__( 'CTA Section', 'bootstrap-coach' ),
            'about'      => esc_html__( 'About Section', 'bootstrap-coach' ),
            'counter'    => esc_html__( 'Counter Section', 'bootstrap-coach' ),
            'newsletter' => esc_html__( 'Newsletter Section', 'bootstrap-coach' ),
            'blogs'      => esc_html__( 'Blog Section', 'bootstrap-coach' ),
        );
    }
    $wp_customize->add_setting( 'bootstrap_coach_sort_homepage', array(
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'bootstrap_coach_sanitize_array',
        'default'           => $default,
    ) );
    $wp_customize->add_control( new Bootstrap_Coach_Control_Sortable($wp_customize, 'bootstrap_coach_sort_homepage', array(
        'label'    => esc_html__( 'Drag and Drop Sections to rearrange.', 'bootstrap-coach' ),
        'section'  => 'bootstrap_coach_sort_homepage_sections',
        'type'     => 'sortable',
        'disabled' => fs_bootstrap_coach()->is_free_plan(),
        'choices'  => $choices,
    )) );
    if ( fs_bootstrap_coach()->is_free_plan() ) {
        $wp_customize->add_setting( 'bootstrap_coach_sort_homepage_upgrade_to_pro', array(
            'sanitize_callback' => null,
        ) );
        $wp_customize->add_control( new Bootstrap_Coach_Control_Upgrade_To_Pro($wp_customize, 'bootstrap_coach_sort_homepage_upgrade_to_pro', array(
            'section'     => 'bootstrap_coach_sort_homepage_sections',
            'settings'    => 'bootstrap_coach_sort_homepage_upgrade_to_pro',
            'title'       => __( 'Rearrange homepage sections and prioritize what your visitors should see first.', 'bootstrap-coach' ),
            'items'       => array(
                'one' => array(
                    'title' => __( 'Rearrange sections on the Homepage', 'bootstrap-coach' ),
                ),
            ),
            'button_url'  => esc_url( 'https://thebootstrapthemes.com/coach/#free-vs-pro' ),
            'button_text' => __( 'Upgrade Now', 'bootstrap-coach' ),
        )) );
    }
}
