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

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

add_action( 'customize_register', 'ogma_register_typography_options' );

if ( ! function_exists( 'ogma_register_typography_options' ) ) :

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

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

        /**
         * Add Typography Section
         * 
         * General Settings > Typography
         * 
         * @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_typography',
                array(
                    'priority'  => 30,
                    'panel'     => 'ogma_panel_general',
                    'title'     => __( 'Typography', 'ogma' ),
                )
            )
        );

        /**
         * Body Typography Section
         *
         * General Settings > Typography > Body
         *
         * @since 1.0.0
         */
        $wp_customize->add_section( new Ogma_Customize_Section(
            $wp_customize, 'ogma_section_typography_body',
                array(
                    'priority'      => 10,
                    'panel'         => 'ogma_panel_general',
                    'section'       => 'ogma_section_typography',
                    'title'         => __( 'Body', 'ogma' )
                )
            )
        );

        /**
         * Typography Font filed for body typography
         *
         * General Settings > Typography > Body
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting(
            'body_font_family',
            array(
                'default'           => ogma_get_customizer_default( 'body_font_family' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_setting(
            'body_font_weight',
            array(
                'default'           => ogma_get_customizer_default( 'body_font_weight' ),
                'sanitize_callback' => 'sanitize_key',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'body_font_style',
            array(
                'default'           => ogma_get_customizer_default( 'body_font_style' ),
                'sanitize_callback' => 'sanitize_text_field',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'body_font_transform',
            array(
                'default'           => ogma_get_customizer_default( 'body_font_transform' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );
        $wp_customize->add_setting(
            'body_font_decoration',
            array(
                'default'           => ogma_get_customizer_default( 'body_font_decoration' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );

        $wp_customize->add_control( new Ogma_Control_Typography (
            $wp_customize,
                'body_typography',
                array(
                    'priority'      => 10,
                    'section'       => 'ogma_section_typography_body',
                    'settings'      => array(
                        'family'        => 'body_font_family',
                        'weight'        => 'body_font_weight',
                        'style'         => 'body_font_style',
                        'transform'     => 'body_font_transform',
                        'decoration'    => 'body_font_decoration'
                    ),
                    'description'   => __( 'Select how you want your body fonts to appear.', 'ogma' ),
                    'l10n'          => array() // Pass custom labels. Use the setting key (above) for the specific label.
                )
            )
        );

        /**
         * Heading Typography Section
         *
         * General Settings > Typography > Heading
         *
         * @since 1.0.0
         */
        $wp_customize->add_section( new Ogma_Customize_Section(
            $wp_customize, 'ogma_section_typography_heading',
                array(
                    'priority'      => 20,
                    'panel'         => 'ogma_panel_general',
                    'section'       => 'ogma_section_typography',
                    'title'         => __( 'Heading', 'ogma' )
                )
            )
        );

        /**
         * Typography Font filed for heading typography
         *
         * General Settings > Typography > Heading
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting(
            'heading_font_family',
            array(
                'default'           => ogma_get_customizer_default( 'heading_font_family' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_setting(
            'heading_font_weight',
            array(
                'default'           => ogma_get_customizer_default( 'heading_font_weight' ),
                'sanitize_callback' => 'sanitize_key',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'heading_font_style',
            array(
                'default'           => ogma_get_customizer_default( 'heading_font_style' ),
                'sanitize_callback' => 'sanitize_text_field',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'heading_font_transform',
            array(
                'default'           => ogma_get_customizer_default( 'heading_font_transform' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );
        $wp_customize->add_setting(
            'heading_font_decoration',
            array(
                'default'           => ogma_get_customizer_default( 'heading_font_decoration' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );

        $wp_customize->add_control( new Ogma_Control_Typography (
            $wp_customize,
                'heading_typography',
                array(
                    'priority'      => 10,
                    'section'       => 'ogma_section_typography_heading',
                    'settings'      => array(
                        'family'        => 'heading_font_family',
                        'weight'        => 'heading_font_weight',
                        'style'         => 'heading_font_style',
                        'transform'     => 'heading_font_transform',
                        'decoration'    => 'heading_font_decoration'
                    ),
                    'description'   => __( 'Select how you want your body fonts to appear.', 'ogma' ),
                    'l10n'          => array() // Pass custom labels. Use the setting key (above) for the specific label.
                )
            )
        );

        /**
         * Upgrade field for typography section
         * 
         * General Settings > Typography
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'upgrade_typogrpahy',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Ogma_Control_Upgrade(
            $wp_customize, 'upgrade_typogrpahy',
                array(
                    'priority'      => 70,
                    'section'       => 'ogma_section_typography',
                    'settings'      => 'upgrade_typogrpahy',
                    'label'         => __( 'More Options with Ogma Pro', 'ogma' ),
                    'choices'       => ogma_upgrade_choices( 'ogma_typography' )
                )
            )
        );

    }

endif;