<?php 
/**
 * Register custom fonts.
 */
if (!function_exists('edumodo__load_google_fonts_url')) {
    function edumodo__load_google_fonts_url() {
        $font_url = '';

        // body and heading
        $body_typo = get_theme_mod('body_typo',[]);
        $headings_all = get_theme_mod('headings_all',[]);
        $headings_h1 = get_theme_mod('headings_h1',[]);
        $headings_h2 = get_theme_mod('headings_h2',[]);
        $headings_h3 = get_theme_mod('headings_h3',[]);
        $headings_h4 = get_theme_mod('headings_h4',[]);
        $headings_h5 = get_theme_mod('headings_h5',[]);
        $headings_h6 = get_theme_mod('headings_h6',[]);
        // page
        $page_header_title = get_theme_mod('page_header_title',[]);
        $page_header_breadcrumb = get_theme_mod('page_header_breadcrumb',[]);
        // menu & submenu 
        $main_menu_typo = get_theme_mod('main_menu_typo',[]);
        $sub_menu_typo = get_theme_mod('sub_menu_typo',[]);
        // learndash
        $ld_course_archive_title = get_theme_mod('ld_course_archive_title',[]);
        // lifter archive typo variable
        $edumodo__lifter_archive_price_typo = get_theme_mod('edumodo__lifter_archive_price_typo',[]);
        $edumodo__lifter_archive_title_typo = get_theme_mod('edumodo__lifter_archive_title_typo',[]);
        $edumodo__lifter_archive_excerpt_typo = get_theme_mod('edumodo__lifter_archive_excerpt_typo',[]);
        $edumodo__lifter_archive_meta_typo = get_theme_mod('edumodo__lifter_archive_meta_typo',[]);
        
        // default archive 
        // teacher 
        $edumodo__lifter_teacher_archive_title_typo = get_theme_mod('edumodo__lifter_teacher_archive_title_typo',[]);
        $edumodo__lifter_teacher_archive_designation_typo = get_theme_mod('edumodo__lifter_teacher_archive_designation_typo',[]);


        /* Translators: If there are any character that are
         * not supported by Poppins, translate this to off, do not
         * translate into your own language.
         */
        $poppins = _x('on', 'Poppins font:on or off', 'edumodo');

        /* Translators: If there are any character that are
         * not supported by Roboto, translate this to off, do not
         * translate into your own language.
         */
        $roboto = _x('on', 'Roboto font:on or off', 'edumodo');

        if ('off' !== $poppins || 'off' !== $roboto) {
            $font_family = array();
            
            # start body typography
                if ( ( (isset($body_typo['font-family']) && $body_typo['font-family']  == 'inherit' ) || empty($body_typo['font-family'])  ) ) {
                    $font_family[] = 'Roboto:400,400i,500,700';
                } else {
                    $font_family[] = $body_typo['font-family'].':'.$body_typo['variant'];
                }
            # end of body typography
            
            # start heading all typography
                if ( (isset($headings_all['font-family']) && $headings_all['font-family']  == 'inherit' ) || empty($headings_all['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $headings_all['font-family'].':'.$headings_all['variant'];
                }
            # end of heading all typography

            # start all heading typography
                if( !empty($headings_h1['font-family']) &&  $headings_h1['font-family'] != 'inherit' ) {
                    $font_family[] = $headings_h1['font-family'].':'.$headings_h1['variant'];
                }

                if(!empty($headings_h2['font-family']) &&  $headings_h2['font-family'] != 'inherit'  ) {
                    $font_family[] = $headings_h2['font-family'].':'.$headings_h2['variant'];
                }

                if(!empty($headings_h3['font-family']) &&  $headings_h3['font-family'] != 'inherit'  ) {
                    $font_family[] = $headings_h3['font-family'].':'.$headings_h3['variant'];
                }

                if(!empty($headings_h4['font-family'])&&  $headings_h4['font-family'] != 'inherit' ) {
                    $font_family[] = $headings_h4['font-family'].':'.$headings_h4['variant'];
                }

                if(!empty($headings_h5['font-family']) &&  $headings_h5['font-family'] != 'inherit' ) {
                    $font_family[] = $headings_h5['font-family'].':'.$headings_h5['variant'];
                }

                if(!empty($headings_h6['font-family']) &&  $headings_h6['font-family'] != 'inherit' ) {
                    $font_family[] = $headings_h6['font-family'].':'.$headings_h6['variant'];
                }
            # end of all heading typography

            # start page header typography
                // page header title typography
                if ( (isset($page_header_title['font-family']) && $page_header_title['font-family']  == 'inherit' ) || empty($page_header_title['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $page_header_title['font-family'].':'.$page_header_title['variant'];
                }
                // page header breadcrumb typography
                if ( (isset($page_header_breadcrumb['font-family']) && $page_header_breadcrumb['font-family']  == 'inherit' ) || empty($page_header_breadcrumb['font-family']) ) {
                    $font_family[] = 'Roboto:400,400i,500,700';
                } else {
                    $font_family[] = $page_header_breadcrumb['font-family'].':'.$page_header_breadcrumb['variant'];
                }
            # end of page header typography

            # start menu typography
                // Main Menu typography
                if ( (isset($main_menu_typo['font-family']) && $main_menu_typo['font-family']  == 'inherit' ) || empty($main_menu_typo['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $main_menu_typo['font-family'].':'.$main_menu_typo['variant'];
                }
                // Sub Menu typography
                if ( (isset($sub_menu_typo['font-family']) && $sub_menu_typo['font-family']  == 'inherit' ) || empty($sub_menu_typo['font-family']) ) {
                    $font_family[] = 'Roboto:400,400i,500,700';
                } else {
                    $font_family[] = $sub_menu_typo['font-family'].':'.$sub_menu_typo['variant'];
                }
            # end of menu typography

            # start learndash typography
                if ( (isset($ld_course_archive_title['font-family']) && $ld_course_archive_title['font-family']  == 'inherit' ) || empty($ld_course_archive_title['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $ld_course_archive_title['font-family'].':'.$ld_course_archive_title['variant'];
                }
            # end of learndash typography

            # start lifter archive typography
                // price 
                if ( (isset($edumodo__lifter_archive_price_typo['font-family']) && $edumodo__lifter_archive_price_typo['font-family']  == 'inherit' ) || empty($edumodo__lifter_archive_price_typo['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $edumodo__lifter_archive_price_typo['font-family'].':'.$edumodo__lifter_archive_price_typo['variant'];
                }
                // title
                if ( (isset($edumodo__lifter_archive_title_typo['font-family']) && $edumodo__lifter_archive_title_typo['font-family']  == 'inherit' ) || empty($edumodo__lifter_archive_title_typo['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $edumodo__lifter_archive_title_typo['font-family'].':'.$edumodo__lifter_archive_title_typo['variant'];
                }
                // excerpt
                if ( (isset($edumodo__lifter_archive_excerpt_typo['font-family']) && $edumodo__lifter_archive_excerpt_typo['font-family']  == 'inherit' ) || empty($edumodo__lifter_archive_excerpt_typo['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $edumodo__lifter_archive_excerpt_typo['font-family'].':'.$edumodo__lifter_archive_excerpt_typo['variant'];
                }
                // meta
                if ( (isset($edumodo__lifter_archive_meta_typo['font-family']) && $edumodo__lifter_archive_meta_typo['font-family']  == 'inherit' ) || empty($edumodo__lifter_archive_meta_typo['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $edumodo__lifter_archive_meta_typo['font-family'].':'.$edumodo__lifter_archive_meta_typo['variant'];
                }
            # end of lifter archive typography

            # default Archive
                if ( (isset($edumodo__lifter_teacher_archive_title_typo['font-family']) && $edumodo__lifter_teacher_archive_title_typo['font-family']  == 'inherit' ) || empty($edumodo__lifter_teacher_archive_title_typo['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $edumodo__lifter_teacher_archive_title_typo['font-family'].':'.$edumodo__lifter_teacher_archive_title_typo['variant'];
                }

                if ( (isset($edumodo__lifter_teacher_archive_designation_typo['font-family']) && $edumodo__lifter_teacher_archive_designation_typo['font-family']  == 'inherit' ) || empty($edumodo__lifter_teacher_archive_designation_typo['font-family']) ) {
                    $font_family[] = 'Poppins:400,500,500i,700,800';
                } else {
                    $font_family[] = $edumodo__lifter_teacher_archive_designation_typo['font-family'].':'.$edumodo__lifter_teacher_archive_designation_typo['variant'];
                }
            # end of default archive

            $query_args = array(
                'family' => urlencode(implode('|', $font_family)),
            );

            $font_url = add_query_arg($query_args, 'https://fonts.googleapis.com/css');
        }

        return $font_url;
    }
}

if(! function_exists('edumodo__enqueue_google_fonts') ){
    function edumodo__enqueue_google_fonts(){
        wp_enqueue_style('edumodo__load_google_fonts_url',edumodo__load_google_fonts_url());
    }
}

add_editor_style(array('dist/css/editor-styles.css', edumodo__load_google_fonts_url()));
add_action('wp_enqueue_scripts', 'edumodo__enqueue_google_fonts');

?>