<?php

/**
 * Rearrange Sections
 *
 * @package relax_spa
 */
add_action( 'customize_register', 'relax_spa_sort_homepage_sections' );
function relax_spa_sort_homepage_sections(  $wp_customize  ) {
    $wp_customize->add_section( 'relax_spa_sort_homepage_sections', array(
        'title'       => esc_html__( 'Rearrange Home Sections', 'relax-spa' ),
        'description' => esc_html__( 'Rearrange Home Sections', 'relax-spa' ),
        'panel'       => '',
        'priority'    => 13,
    ) );
    if ( class_exists( 'The_Bootstrap_Themes_Companion' ) ) {
        $default = array(
            'services',
            'who-we-are',
            'counter',
            'why-choose-us',
            'testimonial',
            'teams',
            'price'
        );
        $choices = array(
            'services'      => esc_html__( 'Service Section', 'relax-spa' ),
            'who-we-are'    => esc_html__( 'Who we are Sections', 'relax-spa' ),
            'counter'       => esc_html__( 'Counter Section', 'relax-spa' ),
            'why-choose-us' => esc_html__( 'Why choose us Section', 'relax-spa' ),
            'testimonial'   => esc_html__( 'Testimonial Section', 'relax-spa' ),
            'teams'         => esc_html__( 'Teams Section', 'relax-spa' ),
            'price'         => esc_html__( 'Price Section', 'relax-spa' ),
        );
    } else {
        $default = array(
            'services',
            'who-we-are',
            'counter',
            'why-choose-us'
        );
        $choices = array(
            'services'      => esc_html__( 'Service Section', 'relax-spa' ),
            'who-we-are'    => esc_html__( 'Who we are Sections', 'relax-spa' ),
            'counter'       => esc_html__( 'Counter Section', 'relax-spa' ),
            'why-choose-us' => esc_html__( 'Why choose us Section', 'relax-spa' ),
        );
    }
    $wp_customize->add_setting( 'relax_spa_sort_homepage', array(
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'relax_spa_sanitize_array',
        'default'           => $default,
    ) );
    $wp_customize->add_control( new Relax_Spa_Control_Sortable($wp_customize, 'relax_spa_sort_homepage', array(
        'label'    => esc_html__( 'Drag and Drop Sections to rearrange.', 'relax-spa' ),
        'section'  => 'relax_spa_sort_homepage_sections',
        'disabled' => fs_relax_spa()->is_free_plan(),
        'choices'  => $choices,
    )) );
    if ( fs_relax_spa()->is_free_plan() ) {
        $wp_customize->add_setting( 'relax_spa_sort_homepage_upgrade_to_pro', array(
            'sanitize_callback' => null,
        ) );
        $wp_customize->add_control( new Relax_Spa_Control_Upgrade_To_Pro($wp_customize, 'relax_spa_sort_homepage_upgrade_to_pro', array(
            'section'     => 'relax_spa_sort_homepage_sections',
            'settings'    => 'relax_spa_sort_homepage_upgrade_to_pro',
            'title'       => __( 'Rearrange homepage sections and prioritize what your visitors should see first.', 'relax-spa' ),
            'items'       => array(
                'one' => array(
                    'title' => __( 'Rearrange sections on the Homepage', 'relax-spa' ),
                ),
            ),
            'button_url'  => esc_url( 'https://thebootstrapthemes.com/relax-spa/#free-vs-pro' ),
            'button_text' => __( 'Upgrade Now', 'relax-spa' ),
        )) );
    }
}
