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

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

add_action( 'customize_register', 'purenote_register_page_error_options' );

if ( ! function_exists( 'purenote_register_page_error_options' ) ) :

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

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

       /**
         * 404 Error Section
         * 
         * Innerpage Settings > 404 Error
         * 
         * @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_page_error',
                array(
                    'priority'  => 35,
                    'panel'     => 'purenote_panel_inner_page',
                    'title'     => __( '404 Error', 'purenote' ),
                )
            )
        );

        /**
         * Toggle option for search form in 404 error page.
         *
         * Innerpage Settings > 404 Error
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_error_page_search_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_error_page_search_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_error_page_search_enable',
                array(
                    'priority'          => 10,
                    'section'           => 'purenote_section_page_error',
                    'settings'          => 'purenote_error_page_search_enable',
                    'label'             => __( 'Enable Search box', 'purenote' )
                )
            )
        );

        /**
         * Toggle option for homepage button.
         *
         * Innerpage Settings > 404 Error
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_error_page_button_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_error_page_button_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_error_page_button_enable',
                array(
                    'priority'          => 20,
                    'section'           => 'purenote_section_page_error',
                    'settings'          => 'purenote_error_page_button_enable',
                    'label'             => __( 'Enable homepage button', 'purenote' )
                )
            )
        );

        /**
         * Text field for homepage button label
         *
         * Innerpage Settings > 404 Error
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_error_page_button_label',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_error_page_button_label' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control (
            $wp_customize, 'purenote_error_page_button_label',
                array(
                    'priority'          => 25,
                    'section'           => 'purenote_section_page_error',
                    'settings'          => 'purenote_error_page_button_label',
                    'label'             => __( 'Button Label', 'purenote' ),
                    'type'              => 'text',
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_error_page_button_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );
    }

endif;