<?php

/**
 * Rearrange Sections
 *
 * @package Chic Lifestyle
 */

add_action('customize_register', 'chic_lifestyle_sort_homepage_sections');

function chic_lifestyle_sort_homepage_sections($wp_customize) {

    // Add Drag and Drop Section.
    $wp_customize->add_section('chic_lifestyle_sort_homepage_sections', array(
        'title'       => esc_html__('Rearrange Home Sections', 'chic-lifestyle'),
        'description' => esc_html__('Rearrange Home Sections', 'chic-lifestyle'),
        'priority'    => 15,
        'capability'     => 'edit_theme_options',
    ));

    // Add sortable setting.
    $wp_customize->add_setting('chic_lifestyle_sort_homepage', array(
        'default'           => array(
            'slider-section',
            'card-section',
            'featured-section',
            'instagram-section',
            'blog-section',
        ),
        'sanitize_callback' => 'chic_lifestyle_sanitize_array',
    ));

    // Add sortable control.
    // NOTE: You need to implement the Chic_Lifestyle_Sortable_Control custom control.
    $wp_customize->add_control(new Chic_Lifestyle_Control_Sortable($wp_customize, 'chic_lifestyle_sort_homepage', array(
        'label'    => esc_html__('Drag and Drop Sections to rearrange.', 'chic-lifestyle'),
        'section'  => 'chic_lifestyle_sort_homepage_sections',
        'settings' => 'chic_lifestyle_sort_homepage',
        'type'     => 'sortable',
        'disabled'     => fs_chic_lifestyle()->is_free_plan(),
        'choices'  => array(
            'slider-section'       => esc_html__('Slider Section', 'chic-lifestyle'),
            'card-section'          => esc_html__('Card Section', 'chic-lifestyle'),
            'featured-section'      => esc_html__('Featured Posts Section', 'chic-lifestyle'),
            'instagram-section'    => esc_html__('Instagram Section', 'chic-lifestyle'),
            'blog-section'         => esc_html__('Blog Section', 'chic-lifestyle'),
        ),
        'priority' => 10,
    )));

    if ( fs_chic_lifestyle()->is_free_plan() ) {
        $wp_customize->add_setting( 'chic_lifestyle_sort_homepage_upgrade_to_pro', array(
            'sanitize_callback' => null,
        ) );
        $wp_customize->add_control( new Chic_Lifestyle_Control_Upgrade_To_Pro(
          $wp_customize, 'chic_lifestyle_sort_homepage_upgrade_to_pro', array(
            'section' => 'chic_lifestyle_sort_homepage_sections',
            'settings'    => 'chic_lifestyle_sort_homepage_upgrade_to_pro',
            'title'   => __( 'Rearrange homepage sections and prioritize what your visitors should see first.', 'chic-lifestyle' ),
            'button_url'   => esc_url( 'https://thebootstrapthemes.com/chic-lifestyle/#free-vs-pro' ),
            'button_text'   => __( 'Upgrade Now', 'chic-lifestyle' ),
          )
        ) );
    }
}