<?php
/**
 * Archive Page and it's fields inside Innerpage Settings panel.
 * 
 * @package Ogma
 */

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

add_action( 'customize_register', 'ogma_register_archive_options' );

if ( ! function_exists( 'ogma_register_archive_options' ) ) :

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

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

        /**
         * Archive Section
         * 
         * Innerpage Settings > Archive Pages
         * 
         * @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 Ogma_Customize_Section (
            $wp_customize, 'ogma_section_page_archive',
                array(
                    'priority'  => 5,
                    'panel'     => 'ogma_panel_innerpage',
                    'title'     => __( 'Archive Pages', 'ogma' ),
                )
            )
        );

        /**
         * Select option for archive page style
         *
         * Innerpage Settings > Archive Pages
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'archive_page_style',
            array(
                'default'           => ogma_get_customizer_default( 'archive_page_style' ),
                'sanitize_callback' => 'ogma_sanitize_select'
            )
        );
        $wp_customize->add_control( 'archive_page_style',
            array(
                'priority'          => 10,
                'section'           => 'ogma_section_page_archive',
                'settings'          => 'archive_page_style',
                'label'             => __( 'Archive Page Style', 'ogma' ),
                'type'              => 'select',
                'choices'           => ogma_archive_page_style_choices()
            )
        );

        /**
         * Toggle option for archive title prefix.
         *
         * Innerpage Settings > Archive Pages
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'archive_title_prefix_enable',
            array(
                'default'           => ogma_get_customizer_default( 'archive_title_prefix_enable' ),
                'sanitize_callback' => 'ogma_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Ogma_Control_Toggle(
            $wp_customize, 'archive_title_prefix_enable',
                array(
                    'priority'      => 15,
                    'section'       => 'ogma_section_page_archive',
                    'settings'      => 'archive_title_prefix_enable',
                    'label'         => __( 'Enable archive page title prefix.', 'ogma' )
                )
            )
        );

        /**
         * Toggle option for archive post read more.
         *
         * Innerpage Settings > Archive Pages
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'archive_post_readmore_enable',
            array(
                'default'           => ogma_get_customizer_default( 'archive_post_readmore_enable' ),
                'sanitize_callback' => 'ogma_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Ogma_Control_Toggle(
            $wp_customize, 'archive_post_readmore_enable',
                array(
                    'priority'      => 25,
                    'section'       => 'ogma_section_page_archive',
                    'settings'      => 'archive_post_readmore_enable',
                    'label'         => __( 'Enable read more.', 'ogma' )
                )
            )
        );

        /**
         * Upgrade field for archive pages
         * 
         * Innerpage Settings > Archive Pages
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'upgrade_archive',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Ogma_Control_Upgrade(
            $wp_customize, 'upgrade_archive',
                array(
                    'priority'      => 100,
                    'section'       => 'ogma_section_page_archive',
                    'settings'      => 'upgrade_archive',
                    'label'         => __( 'More Features with Ogma Pro', 'ogma' ),
                    'choices'       => ogma_upgrade_choices( 'ogma_archive' )
                )
            )
        );

    }

endif;