<?php
/**
 * Add Performance section and it's fields inside General Settings panel.
 * 
 * @package Blogbuster
 */

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

add_action( 'customize_register', 'blogbuster_register_performance_options' );

if ( ! function_exists( 'blogbuster_register_performance_options' ) ) :

    /**
     * Register theme options for Performance section.
     * 
     * @param WP_Customize_Manager $wp_customize Object that holds the customizer data.
     * @since 1.0.0
     */
    function blogbuster_register_performance_options( $wp_customize ) {

        /*
         * Failsafe is safe
         */
        if ( ! isset( $wp_customize ) ) {
            return;
        }

        /**
         * Add Performance Section
         * 
         * General Settings > Performance
         * 
         * @uses $wp_customize->add_section() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_section/
         * @since 1.0.0
         */
        $wp_customize->add_section( new Blogbuster_Customize_Section (
            $wp_customize, 'blogbuster_section_performance',
                array(
                    'priority'              => 150,
                    'panel'                 => 'blogbuster_panel_general',
                    'title'                 => __( 'Performance', 'blogbuster' ),
                )
            )
        );

        /**
         * Heading field for SEO performance
         *
         * General Settings > Performance > SEO
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'seo_performance_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Heading(
            $wp_customize, 'seo_performance_heading',
                array(
                    'priority'      => 5,
                    'section'       => 'blogbuster_section_performance',
                    'settings'      => 'seo_performance_heading',
                    'label'         => __( 'SEO', 'blogbuster' ),
                )
            )
        );

        /**
         * Toggle option for schema ready.
         *
         * General Settings > Performance
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_site_schema_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_site_schema_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_site_schema_enable',
                array(
                    'priority'      => 10,
                    'section'       => 'blogbuster_section_performance',
                    'settings'      => 'blogbuster_site_schema_enable',
                    'label'         => __( 'Make a website schema ready.', 'blogbuster' )
                )
            )
        );

    }

endif;