<?php
/**
 * Adds the Typography section and its fields to the General Settings panel.
 * 
 * @package PureNote
 */

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

add_action( 'customize_register', 'purenote_register_typography_options' );

if ( ! function_exists( 'purenote_register_typography_options' ) ) :

    /**
     * Registers theme options for the Typography section.
     * 
     * @param WP_Customize_Manager $wp_customize Customizer object.
     * @since 1.0.0
     */
    function purenote_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 Purenote_Customize_Section (
            $wp_customize, 'purenote_section_typography',
                array(
                    'priority'  => 30,
                    'panel'     => 'purenote_panel_general',
                    'title'     => __( 'Typography', 'purenote' ),
                )
            )
        );

        /**
         * Body Typography Section
         *
         * General Settings > Typography > Body
         *
         * @since 1.0.0
         */
        $wp_customize->add_section( new Purenote_Customize_Section(
            $wp_customize, 'purenote_section_typography_body',
                array(
                    'priority'      => 10,
                    'panel'         => 'purenote_panel_general',
                    'section'       => 'purenote_section_typography',
                    'title'         => __( 'Body', 'purenote' )
                )
            )
        );

        /**
         * Typography Font filed for body typography
         *
         * General Settings > Typography > Body
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting(
            'purenote_body_font_family',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_body_font_family' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_setting(
            'purenote_body_font_weight',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_body_font_weight' ),
                'sanitize_callback' => 'sanitize_key',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'purenote_body_font_style',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_body_font_style' ),
                'sanitize_callback' => 'sanitize_text_field',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'purenote_body_font_transform',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_body_font_transform' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );
        $wp_customize->add_setting(
            'purenote_body_font_decoration',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_body_font_decoration' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );

        $wp_customize->add_control( new Purenote_Control_Typography (
            $wp_customize,
                'body_typography',
                array(
                    'priority'      => 10,
                    'section'       => 'purenote_section_typography_body',
                    'settings'      => array(
                        'family'        => 'purenote_body_font_family',
                        'weight'        => 'purenote_body_font_weight',
                        'style'         => 'purenote_body_font_style',
                        'transform'     => 'purenote_body_font_transform',
                        'decoration'    => 'purenote_body_font_decoration'
                    ),
                    'description'   => __( 'Choose how you want the body font to appear.', 'purenote' ),
                    '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 Purenote_Customize_Section(
            $wp_customize, 'purenote_section_typography_heading',
                array(
                    'priority'      => 20,
                    'panel'         => 'purenote_panel_general',
                    'section'       => 'purenote_section_typography',
                    'title'         => __( 'Heading', 'purenote' )
                )
            )
        );

        /**
         * Typography Font filed for heading typography
         *
         * General Settings > Typography > Heading
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting(
            'purenote_heading_font_family',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_heading_font_family' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_setting(
            'purenote_heading_font_weight',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_heading_font_weight' ),
                'sanitize_callback' => 'sanitize_key',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'purenote_heading_font_style',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_heading_font_style' ),
                'sanitize_callback' => 'sanitize_text_field',
                'transport'         => 'postMessage'
            )
        );
        $wp_customize->add_setting(
            'purenote_heading_font_transform',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_heading_font_transform' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );
        $wp_customize->add_setting(
            'purenote_heading_font_decoration',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_heading_font_decoration' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
                
            )
        );

        $wp_customize->add_control( new Purenote_Control_Typography (
            $wp_customize,
                'heading_typography',
                array(
                    'priority'      => 10,
                    'section'       => 'purenote_section_typography_heading',
                    'settings'      => array(
                        'family'        => 'purenote_heading_font_family',
                        'weight'        => 'purenote_heading_font_weight',
                        'style'         => 'purenote_heading_font_style',
                        'transform'     => 'purenote_heading_font_transform',
                        'decoration'    => 'purenote_heading_font_decoration'
                    ),
                    'description'   => __( 'Choose how you want the header font to appear.', 'purenote' ),
                    'l10n'          => array() // Pass custom labels. Use the setting key (above) for the specific label.
                )
            )
        );

    }

endif;