<?php
/**
 * Single Posts and it's fields inside Innerpage Settings panel.
 * 
 * @package Purenote
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
add_action( 'customize_register', 'purenote_register_single_posts_options' );

if( !function_exists( 'purenote_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 purenote_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 Purenote_Customize_Section(
            $wp_customize, 'purenote_section_post_single',
                array(
                    'priority'  => 15,
                    'panel'     => 'purenote_panel_inner_page',
                    'title'     => __( 'Single Posts', 'purenote' ),
                )
            )
        );

        /**
         * Heading field for posts layout
         * 
         * Innerpage Settings > Single Posts
         * 
         * @since 1.0.0
         */
        $wp_customize-> add_setting( 'purenote_single_posts_layout_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize-> add_control( new Purenote_Control_Heading (
            $wp_customize, 'purenote_single_posts_layout_heading',
                array(
                    'priority'  => 15,
                    'section'   => 'purenote_section_post_single',
                    'settings'  => 'purenote_single_posts_layout_heading',
                    'label' => __( 'Posts Layout', 'purenote' )
                )
            )
        );

        /**
         * Radio image field for single posts layout
         * 
         * Innerpage Settings > Single Posts
         * 
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_single_posts_layout',
            array(
                'default'   => purenote_get_customizer_default( 'purenote_single_posts_layout' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize-> add_control( new Purenote_Control_Radio_Image(
            $wp_customize, 'purenote_single_posts_layout',
                array(
                    'priority'  => 15,
                    'section'   => 'purenote_section_post_single',
                    'settings'  => 'purenote_single_posts_layout',
                    'label'     => __( 'Posts Layout', 'purenote' ),
                    'choices'   => purenote_single_posts_layout_choices(),
                )
            )
        );

        /**
         * Heading field for posts author box
         * Innerpage Settings > Single Posts
         * 
         * @since 1.0.0
         */
        $wp_customize-> add_setting( 'single_posts_author_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize-> add_control( new Purenote_Control_Heading(
            $wp_customize, 'single_posts_author_heading',
                array(
                    'priority'  => 25,
                    'section'   => 'purenote_section_post_single',
                    'settings'  => 'single_posts_author_heading',
                    'label' => __( 'Author Box', 'purenote' )
                )
            )
        );

        /**
         * Toggle option for single posts author box
         * 
         * Innerpage Settings > Single Posts
         * 
         * @since 1.0.0
         */
        $wp_customize-> add_setting( 'purenote_single_posts_author_enable',
            array(
                'default'   => purenote_get_customizer_default( 'purenote_single_posts_author_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize-> add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_single_posts_author_enable',
                array(
                    'priority'  => 25,
                    'section'   => 'purenote_section_post_single',
                    'settings'  => 'purenote_single_posts_author_enable',
                    'label'     => __( 'Enable author box', 'purenote' )
                )
            )
        );

        /**
         * Heading field for related posts
         * 
         * Innerpage Settings > Single Posts
         * 
         * @since 1.0.0
         */
        $wp_customize-> add_setting( 'single_posts_related_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize-> add_control( new Purenote_Control_Heading(
            $wp_customize, 'single_posts_related_heading',
                array(
                    'priority'  => 45,
                    'section'   => 'purenote_section_post_single',
                    'settings'  => 'single_posts_related_heading',
                    'label'     => __( 'Related Posts', 'purenote' )
                )
            )
        );
        /**
         * Toggle option for single posts related posts
         * 
         * Innerpage Settings > Single Posts
         * 
         * @since 1.0.0
         */
        $wp_customize -> add_setting('purenote_single_posts_related_enable',
            array(
                'default'   => purenote_get_customizer_default( 'purenote_single_posts_related_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize-> add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_single_posts_related_enable',
                array(
                    'priority'  => 45,
                    'section'   => 'purenote_section_post_single',
                    'settings'  => 'purenote_single_posts_ralated_enable',
                    'label'     => __( 'Enable related posts', 'purenote' )
                )
            )
        );

        /**
         * Text field for related posts section title
         * 
         * Innerpage Settings  > Single Posts
         * 
         * @since 1.0.0
         */
        $wp_customize-> add_setting( 'purenote_single_posts_related_label',
            array(
                'default'   => purenote_get_customizer_default( 'purenote_single_posts_related_label' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize-> add_control( 'purenote_single_posts_related_label',
            array(
                'priority'   => 50,
                'section'    => 'purenote_section_post_single',
                'settings'   => 'purenote_single_posts_related_label',
                'label'      => __( 'Section Title', 'purenote' ),
                'type'       => 'text',
            )
        );
    }

endif;