<?php

/**
 * Dark Fitness Theme Customizer
 *
 * @package dark_fitness
 */

// Sanitize callback.
require get_template_directory() . '/inc/customizer/sanitize-callback.php';

// Active Callback.
require get_template_directory() . '/inc/customizer/active-callback.php';

// Custom Controls.
require get_template_directory() . '/inc/customizer/custom-controls/custom-controls.php';
// Icon Controls.
require get_template_directory() . '/inc/customizer/custom-controls/icon-control.php';

if ( ! defined( 'DARK_FITNESS_UPSELL_LINK' ) ) {define('DARK_FITNESS_UPSELL_LINK',__('https://asterthemes.com/products/fitness-wordpress-theme','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_UPSELL_TEXT' ) ) {define( 'DARK_FITNESS_UPSELL_TEXT', __( 'Fitness Pro','dark-fitness' ));}
if ( ! defined( 'DARK_FITNESS_DOC_LINK' ) ) {define('DARK_FITNESS_DOC_LINK',__('https://demo.asterthemes.com/docs/dark-fitness-free','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_UPSELL_DOC_TEXT' ) ) {define( 'DARK_FITNESS_UPSELL_DOC_TEXT', __( 'Documentation','dark-fitness' ));}
if ( ! defined( 'DARK_FITNESS_UPSELL_COLOR' ) ) {define( 'DARK_FITNESS_UPSELL_COLOR', __( '#c1e503','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_DEMO_URL' ) ) {define('DARK_FITNESS_DEMO_URL',__('https://demo.asterthemes.com/fitness-wordpress-theme','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_SUPPORT_URL' ) ) {define('DARK_FITNESS_SUPPORT_URL',__('https://wordpress.org/support/theme/dark-fitness','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_REVIEW_URL' ) ) {define('DARK_FITNESS_REVIEW_URL',__('https://wordpress.org/support/theme/dark-fitness/reviews/#new-post','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_PRO_DOC_URL' ) ) {define('DARK_FITNESS_PRO_DOC_URL',__('https://demo.asterthemes.com/docs/dark-fitness-pro','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_FREE_DOC_URL' ) ) {define('DARK_FITNESS_FREE_DOC_URL',__('https://demo.asterthemes.com/docs/dark-fitness-free','dark-fitness'));}
if ( ! defined( 'DARK_FITNESS_DEMO_IMPORT_URL' ) ) {
	define( 'DARK_FITNESS_DEMO_IMPORT_URL', esc_url( admin_url( 'themes.php?page=darkfitness-wizard' ) ) );
}
if ( ! defined( 'DARK_FITNESS_WELCOME_MESSAGE' ) ) {
	define( 'DARK_FITNESS_WELCOME_MESSAGE', __( 'Welcome to Dark Fitness', 'dark-fitness' ) );
}

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function dark_fitness_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
	

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'dark_fitness_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'dark_fitness_customize_partial_blogdescription',
			)
		);
	}

	// Upsell Section.
	$wp_customize->add_section(
		new Dark_Fitness_Upsell_Section(
			$wp_customize,
			'upsell_section',
			array(
				'title'            => esc_html( DARK_FITNESS_UPSELL_TEXT, 'dark-fitness' ),
				'button_text'      => __( 'Buy Pro', 'dark-fitness' ),
				'url'              => esc_url( DARK_FITNESS_UPSELL_LINK ),
				'background_color' => esc_attr( DARK_FITNESS_UPSELL_COLOR ),
				'text_color'       => '#fff',
				'priority'         => 0,
			)
		)
	);

	$wp_customize->add_section(
		new Dark_Fitness_Upsell_Section(
			$wp_customize,
			'doc_section',
			array(
				'title'            => esc_html( DARK_FITNESS_UPSELL_DOC_TEXT, 'dark-fitness' ),
				'button_text'      => __( 'Free Doc', 'dark-fitness' ),
				'url'              => esc_url( DARK_FITNESS_DOC_LINK ),
				'background_color' => esc_attr( DARK_FITNESS_UPSELL_COLOR ),
				'text_color'       => '#fff',
				'priority'         => 0,
			)
		)
	);

	// Theme Options.
	require get_template_directory() . '/inc/customizer/theme-options.php';

	// Front Page Options.
	require get_template_directory() . '/inc/customizer/front-page-options.php';

}
add_action( 'customize_register', 'dark_fitness_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function dark_fitness_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function dark_fitness_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function dark_fitness_customize_preview_js() {
	// Append .min if SCRIPT_DEBUG is false.
	$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

	wp_enqueue_script( 'dark-fitness-customizer', get_template_directory_uri() . '/assets/js/customizer' . $min . '.js', array( 'customize-preview' ), DARK_FITNESS_VERSION, true );
}
add_action( 'customize_preview_init', 'dark_fitness_customize_preview_js' );

/**
 * Enqueue script for custom customize control.
 */
function dark_fitness_custom_control_scripts() {
	// Append .min if SCRIPT_DEBUG is false.
	$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

	wp_enqueue_style( 'dark-fitness-custom-controls-css', get_template_directory_uri() . '/assets/css/custom-controls' . $min . '.css', array(), '1.0', 'all' );

	wp_enqueue_script( 'dark-fitness-custom-controls-js', get_template_directory_uri() . '/assets/js/custom-controls' . $min . '.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), '1.0', true );
}
add_action( 'customize_controls_enqueue_scripts', 'dark_fitness_custom_control_scripts' );