<?php
/**
 * Single Post settings and their fields inside the Innerpage Settings panel.
 * 
 * @package Blogbuster
 */

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

add_action( 'customize_register', 'blogbuster_register_single_posts_options' );

if ( ! function_exists( 'blogbuster_register_single_posts_options' ) ) :

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

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

        /**
         * Single Posts Section
         * 
         * Innerpage Settings > Single Posts
         * 
         * @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_post_single',
                array(
                    'priority'  => 15,
                    'panel'     => 'blogbuster_panel_innerpage',
                    'title'     => __( 'Single Posts', 'blogbuster' ),
                )
            )
        );

        /**
         * Toggle option for single posts author box
         *
         * Innerpage Settings > Single Posts
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_single_posts_author_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_single_posts_author_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_single_posts_author_enable',
                array(
                    'priority'          => 15,
                    'section'           => 'blogbuster_section_post_single',
                    'settings'          => 'blogbuster_single_posts_author_enable',
                    'label'             => __( 'Enable author box', 'blogbuster' )
                )
            )
        );

        /**
         * Toggle option for single posts related posts
         *
         * Innerpage Settings > Single Posts
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_single_posts_related_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_single_posts_related_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_single_posts_related_enable',
                array(
                    'priority'          => 25,
                    'section'           => 'blogbuster_section_post_single',
                    'settings'          => 'blogbuster_single_posts_related_enable',
                    'label'             => __( 'Enable related posts', 'blogbuster' )
                )
            )
        );

        /**
         * Text field for related posts section title
         *
         * Innerpage Settings > Single Posts
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_single_posts_related_label',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_single_posts_related_label' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Customize_Control (
            $wp_customize, 'blogbuster_single_posts_related_label',
                array(
                    'priority'          => 50,
                    'section'           => 'blogbuster_section_post_single',
                    'settings'          => 'blogbuster_single_posts_related_label',
                    'label'             => __( 'Section Title', 'blogbuster' ),
                    'type'              => 'text',
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'blogbuster_single_posts_related_enable',
                            'value'    => true,
                            'operator' => '==',
                        )
                    )
                )
            )
        );

        /**
         * Upgrade field for single posts
         * 
         * Innerpage Settings > Single Posts
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'blogbuster_upgrade_single_post',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Upgrade(
            $wp_customize, 'blogbuster_upgrade_single_post',
                array(
                    'priority'      => 100,
                    'section'       => 'blogbuster_section_post_single',
                    'settings'      => 'blogbuster_upgrade_single_post',
                    'label'         => __( 'More Features with Blogbuster Pro', 'blogbuster' ),
                    'choices'       => blogbuster_upgrade_choices( 'blogbuster_single_post' )
                )
            )
        );

    }

endif;