<?php


add_action( 'customize_register', 'chic_lifestyle_typography_section' );

function chic_lifestyle_typography_section( $wp_customize ) {
            
    $wp_customize->add_section( 'chic_lifestyle_typography_section', array(
        'title'          => esc_html__( 'Typography', 'chic-lifestyle' ),
        'description'    => esc_html__( 'Typography', 'chic-lifestyle' ),
        'panel'          => 'chic_lifestyle_general_panel',
        'priority'       => 2,
    ) );

    $wp_customize->add_setting( 'font_family', array(
        'capability'  => 'edit_theme_options',
        'default'     => 'Montserrat',
        'sanitize_callback' => 'chic_lifestyle_sanitize_google_fonts',
    ) );

    $wp_customize->add_control( 'font_family', array(
        'settings'    => 'font_family',
        'label'       =>  esc_html__( 'Choose Font Family For Your Site', 'chic-lifestyle' ),
        'section'     => 'chic_lifestyle_typography_section',
        'type'        => 'select',
        'choices'     => google_fonts(),
        'priority'    => 100
    ) );

    $wp_customize->add_setting( 'font_size', array(
      'capability'  => 'edit_theme_options',
      'default'     => '13px',
      'sanitize_callback' => 'chic_lifestyle_sanitize_select',
    ) );
    
    $wp_customize->add_control( 'font_size', array(
        'settings'    => 'font_size',
        'label'       =>  esc_html__( 'Choose Font Size', 'chic-lifestyle' ),
        'section'     => 'chic_lifestyle_typography_section',
        'type'        => 'select',
        'default'     => '13px',
        'choices'     =>  array(             
                        '13px' => '13px',
                        '14px' => '14px',
                        '15px' => '15px',
                        '16px' => '16px',
                        '17px' => '17px',
                        '18px' => '18px',
                    ),
        'priority'    =>  101
    ) );

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

    $wp_customize->add_control( new Chic_Lifestyle_Slider_Control( $wp_customize, 'chic_lifestyle_font_weight', array(
        'section' => 'chic_lifestyle_typography_section',
        'settings' => 'chic_lifestyle_font_weight',
        'label'   => esc_html__( 'Font Weight', 'chic-lifestyle' ),
        'priority' => 102,
        'choices'     => array(
            'min'  => 100,
            'max'  => 900,
            'step' => 100,
        ),
    ) ) );

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

    $wp_customize->add_control( new Chic_Lifestyle_Slider_Control( $wp_customize, 'chic_lifestyle_line_height', array(
        'section' => 'chic_lifestyle_typography_section',
        'settings' => 'chic_lifestyle_line_height',
        'label'   => esc_html__( 'Line Height', 'chic-lifestyle' ),
        'priority' => 102,
        'choices'     => array(
            'min'  => 13,
            'max'  => 53,
            'step' => 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 Chic_Lifestyle_Text_Message_Control( $wp_customize, 'heading_options_text', array(
        'label' => esc_html__( 'Heading Options :', 'chic-lifestyle' ),
        'section' => 'chic_lifestyle_typography_section',
        'settings' => 'heading_options_text',
        'priority'    => 103
    ) ) );

    $wp_customize->add_setting( 'heading_font_family', array(
        'capability'  => 'edit_theme_options',        
        'sanitize_callback' => 'chic_lifestyle_sanitize_google_fonts',
        'default'     => 'Montserrat',
    ) );

    $wp_customize->add_control( 'heading_font_family', array(
        'settings'    => 'heading_font_family',
        'label'       =>  esc_html__( 'Font Family', 'chic-lifestyle' ),
        'section'     => 'chic_lifestyle_typography_section',
        'type'        => 'select',
        'choices'     => google_fonts(),
        'priority'    => 103
    ) );

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

    $wp_customize->add_control( new Chic_Lifestyle_Slider_Control( $wp_customize, 'heading_font_weight', array(
        'section' => 'chic_lifestyle_typography_section',
        'settings' => 'heading_font_weight',
        'label'   => esc_html__( 'Font Weight', 'chic-lifestyle' ),
        'priority' => 103,
        'choices'     => array(
            'min'  => 100,
            'max'  => 900,
            'step' => 100,
        ),
    ) ) );

    $default_size = array(
        '1' =>  35,
        '2' =>  32,
        '3' =>  18,
        '4' =>  17,
        '5' =>  16,
        '6' =>  12,
    );

    for( $i = 1; $i <= 6 ; $i++ ) {

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

        $wp_customize->add_control( 'chic_lifestyle_heading_' . $i . '_size', array(
            'type'  => 'number',
            'section'   => 'chic_lifestyle_typography_section',
            'label' => esc_html__( 'Heading ', 'chic-lifestyle' ) . $i . esc_html__(' Size', 'chic-lifestyle' ),
            'priority' => 104,        
            'input_attrs' => array(
                'min' => 10,
                'max' => 50,
                'step'  =>  1
            ),
        ) );
    }

    if ( fs_chic_lifestyle()->is_free_plan() ) {

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