<?php
/**
 * Performance and asset loading settings
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}

/**
 * Customizer settings for performance
 */
class Multimagazine_Customize_Performance {

	/**
	 * Registers the section and fires the extension hook.
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer manager instance.
	 */
	public static function register_section( $wp_customize ) {
		$wp_customize->add_section(
			'multi_performance',
			array(
				'title'    => __( 'Multi: performance', 'multimagazine' ),
				'priority' => 24,
			)
		);
		do_action( 'multimagazine_customize_multi_performance', $wp_customize );
	}

	/**
	 * Registers the css src setting.
	 */
	public static function register_css_src() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_css_src',
			'multi_performance',
			array(
				'files'  => __( 'From files', 'multimagazine' ),
				'inline' => __( 'Include in document head element', 'multimagazine' ),
			),
			__( 'How to load theme CSS', 'multimagazine' ),
			__( 'Loading CSS from files lets you take advantage of browser caching (better for multi-page sites), but including them in the HTML doesn\'t needs less requests to server (better for one-page sites or landing pages).', 'multimagazine' )
		);
	}

	/**
	 * Registers the defer css setting.
	 */
	public static function register_defer_css() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_defer_css', 'multi_performance', __( 'Defer CSS loading', 'multimagazine' ) );
	}
}

add_action( 'customize_register', array( 'Multimagazine_Customize_Performance', 'register_section' ) );
add_action( 'multimagazine_customize_multi_performance', array( 'Multimagazine_Customize_Performance', 'register_css_src' ), 10 );
add_action( 'multimagazine_customize_multi_performance', array( 'Multimagazine_Customize_Performance', 'register_defer_css' ), 15 );
