<?php

add_action( 'customize_register', 'relax_spa_typography_section' );

function relax_spa_typography_section( $wp_customize ) {

    $wp_customize->add_section( 'relax_spa_typography_section', array(
        'title'          => esc_html__( 'Typography', 'relax-spa' ),
        'description'    => esc_html__( 'Typography', 'relax-spa' ),
        'panel'          => 'relax_spa_general_panel',
        'priority'       => 2,
    ) );
            
    $wp_customize->add_setting( 'body_font_family', array(
        'capability'  => 'edit_theme_options',
        'default'     => 'Mulish',
        'sanitize_callback' => 'relax_spa_sanitize_google_fonts',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( 'body_font_family', array(
        'label'       =>  esc_html__( 'Choose Font Family For Your Site', 'relax-spa' ),
        'section'     => 'relax_spa_typography_section',
        'type'        => 'select',
        'choices'     => relax_spa_google_fonts(),
        'priority'    => 100
    ) );

    $wp_customize->add_setting( 'font_size', array(
      'capability'  => 'edit_theme_options',
      'default'     => '16px',
      'sanitize_callback' => 'relax_spa_sanitize_select',
      'transport' => 'postMessage',
    ) );
    
    $wp_customize->add_control( 'font_size', array(
        'label'       =>  esc_html__( 'Choose Font Size', 'relax-spa' ),
        'section'     => 'relax_spa_typography_section',
        'type'        => 'select',
        'default'     => '16px',
        'choices'     =>  array(             
            '13px' => '13px',
            '14px' => '14px',
            '15px' => '15px',
            '16px' => '16px',
            '17px' => '17px',
            '18px' => '18px',
        ),
        'priority'    =>  101
    ) );

    $wp_customize->add_setting( 'body_font_weight', array(
        'default'           => 400,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( new relax_spa_Slider_Control( $wp_customize, 'body_font_weight', array(
        'section' => 'relax_spa_typography_section',
        'label'   => esc_html__( 'Font Weight', 'relax-spa' ),
        'priority' => 102,
        'choices'     => array(
            'min'  => 100,
            'max'  => 900,
            'step' => 100,
        ),
    ) ) );

    $wp_customize->add_setting( 'body_line_height', array(
        'default'           => 1.5,
        'sanitize_callback' => 'relax_spa_sanitize_float',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( new Relax_Spa_Slider_Control( $wp_customize, 'body_line_height', array(
        'section' => 'relax_spa_typography_section',
        'label'   => esc_html__( 'Line Height', 'relax-spa' ),
        'priority' => 102,
        'choices'     => array(
            'min'   => 0.1,
            'max'   => 3,
            'step'  => 0.1,
        ),
    ) ) );

    $wp_customize->add_setting( 'heading_options_text', array(
      'default' => '',
      'type' => 'customtext',
      'capability' => 'edit_theme_options',
      'transport' => 'refresh',
      'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( new Relax_Spa_Custom_Text(
        $wp_customize, 'heading_options_text', array(
            'label' => esc_html__( 'Heading Options :', 'relax-spa' ),
            'section' => 'relax_spa_typography_section',
            'priority'    => 103
        )
    ) );

    $wp_customize->add_setting( 'topheading_font_family', array(
        'capability'  => 'edit_theme_options',        
        'sanitize_callback' => 'relax_spa_sanitize_google_fonts',
        'default'     => 'Caveat',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( 'topheading_font_family', array(
        'label'       =>  esc_html__( 'Pre-Heading Font Family', 'relax-spa' ),
        'section'     => 'relax_spa_typography_section',
        'type'        => 'select',
        'choices'     => relax_spa_google_fonts(),
        'priority'    => 103
    ) );

    $wp_customize->add_setting( 'relax_spa_topheading_size', array(
      'default'           => 22,
      'sanitize_callback' => 'absint',
      'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( 'relax_spa_topheading_size', array(
      'type'  => 'number',
      'section'   => 'relax_spa_typography_section',
      'label' => esc_html__( 'Pre-Heading Size', 'relax-spa' ),
      'priority' => 104,
      'input_attrs' => array(
        'min' => 10,
        'max' => 50,
        'step'  =>  1
      ),
    ) );

    $wp_customize->add_setting( 'heading_font_family', array(
        'capability'  => 'edit_theme_options',        
        'sanitize_callback' => 'relax_spa_sanitize_google_fonts',
        'default'     => 'Poppins',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( 'heading_font_family', array(
        'label'       =>  esc_html__( 'Heading Font Family', 'relax-spa' ),
        'section'     => 'relax_spa_typography_section',
        'type'        => 'select',
        'choices'     => relax_spa_google_fonts(),
        'priority'    => 105
    ) );

    $wp_customize->add_setting( 'relax_spa_heading_font_weight', array(
        'default'           => 600,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( new Relax_Spa_Slider_Control(
        $wp_customize, 'relax_spa_heading_font_weight', array(
            'section' => 'relax_spa_typography_section',
            'settings' => 'relax_spa_heading_font_weight',
            'label'   => esc_html__( 'Font Weight', 'relax-spa' ),
            'priority' => 106,
            'choices'     => array(
                'min'  => 100,
                'max'  => 900,
                'step' => 100,
            ),
        )
    ) );

    $default_size = array(
        '1' =>  80,
        '2' =>  34,
        '3' =>  30,
        '4' =>  26,
        '5' =>  24,
        '6' =>  18,
    );
        
    for( $i = 1; $i <= 6 ; $i++ ) {

        $wp_customize->add_setting( 'relax_spa_heading_' . $i . '_size', array(
          'default'           => $default_size[$i],
          'sanitize_callback' => 'absint',
          'transport' => 'postMessage',
        ) );

        $wp_customize->add_control( 'relax_spa_heading_' . $i . '_size', array(
          'type'  => 'number',
          'section'   => 'relax_spa_typography_section',
          'label' => esc_html__( 'Heading ', 'relax-spa' ) . $i . esc_html__(' Size', 'relax-spa' ),
          'priority' => 106,
          'input_attrs' => array(
            'min' => 10,
            'max' => 50,
            'step'  =>  1
          ),
        ) );
    }

    if ( fs_relax_spa()->is_free_plan() ) {

        $wp_customize->add_setting( 'relax_spa_typography_upgrade_to_pro', array(
            'sanitize_callback' => null,
        ) );
        $wp_customize->add_control( new Relax_Spa_Control_Upgrade_To_Pro(
            $wp_customize, 'relax_spa_typography_upgrade_to_pro', array(
                'section' => 'relax_spa_typography_section',
                'settings'    => 'relax_spa_typography_upgrade_to_pro',
                'title'   => __( 'Choose fonts that resonate with your target audience.', 'relax-spa' ),
                'items' => array(
                    'one'   => array(
                        'title' => __( 'Select from more than 850 Google Fonts.', 'relax-spa' ),
                    ),
                ),
                'button_url'   => esc_url( 'https://thebootstrapthemes.com/relax-spa/#free-vs-pro' ),
                'button_text'   => __( 'Upgrade Now', 'relax-spa' ),
                'priority'    => 110,
            )
        ) );
    }
}