<?php

if( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

$prefix = BREEK_LITE_THEMEPREFIX . '_';


class BREEK_LITE_Customize_Upgrade extends WP_Customize_Section {

    public $type = 'breek-lite';
    public $pro_text = '';
    public $pro_url = '';

    public function json() {
        $json = parent::json();
        $json['pro_text'] = $this->pro_text;
        $json['pro_url'] = esc_url( $this->pro_url );

        return $json;
    }

    protected function render_template() {
        ?>
        <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
            <h3 class="accordion-section-title">
                <span class="breek-lite-upgrade-title">{{ data.title }}</span>
                <# if ( data.pro_text && data.pro_url ) { #>
                    <a href="{{ data.pro_url }}" class="button button-secondary breek-lite-go-pro" target="_blank" rel="noopener noreferrer">{{ data.pro_text }}</a>
                <# } #>
            </h3>
        </li>
        <?php
    }
}


if( isset( $wp_customize ) && $wp_customize instanceof WP_Customize_Manager ) {
	$wp_customize->register_section_type( 'BREEK_LITE_Customize_Upgrade' );

	/* Upgrade to Pro */
	$wp_customize->add_section( new BREEK_LITE_Customize_Upgrade( $wp_customize, $prefix . 'upgrade_section', array(
		'title'    => esc_html_x( 'Need More Features?', 'admin', 'breek-lite' ),
		'pro_text' => esc_html_x( 'Go Premium', 'admin', 'breek-lite' ),
		'pro_url'  => apply_filters( 'breek_lite_pro_url', 'https://estudiopatagon.com/projects/breek-for-wordpress' ),
		'priority' => 300,
	) ) );

}

function breek_lite_enqueue_control_scripts() {
    wp_enqueue_script( 'breek-lite-customize-controls', BREEK_LITE_THEMEPATH.'/functions/customizer/upgrade-to-pro.js', array( 'customize-controls' ) );
    wp_enqueue_style( 'breek-lite-customize-controls', BREEK_LITE_THEMEPATH.'/functions/customizer/upgrade-to-pro.css' );
}

add_action( 'customize_controls_enqueue_scripts', 'breek_lite_enqueue_control_scripts', 0 );
