<?php
defined( 'ABSPATH' ) or die();

function educrap_theme_setup() {
	/*
     * Make theme available for translation.
     * Translations can be filed in the /languages/ directory.
     * If you're building a theme based on Theme Palace, use a find and replace
     * to change 'educrap' to the name of your theme in all the template files.
     */
    load_theme_textdomain( 'educrap' );

	/* Register custom menu. */
	register_nav_menu( 'primary', esc_html__( 'Primary Menu', 'educrap' ) );

	/* Gutenberg */
	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'align-wide' );
	add_theme_support('responsive-embeds');
	add_theme_support( 'customize-selective-refresh-widgets' );	

	/* Add editor style. */
	add_theme_support( 'editor-styles' );
	add_theme_support( 'dark-editor-style' );
	/*
     * This theme styles the visual editor to resemble the theme style,
     * specifically font, colors, icons, and column width.
    */
    add_editor_style('/assets/css/editor-style.css');

	/* Load editor style. */
	add_editor_style();

	/* Add default posts and comments RSS feed links to head. */
	add_theme_support( 'automatic-feed-links' );

	/* Enable support for Post Thumbnails. */
	add_theme_support( 'post-thumbnails' );

	/* Add title tag support. */
	add_theme_support( 'title-tag' );


    /* Enable support for HTML5 */
    add_theme_support( 'html5', array(
	    'comment-form',
	    'comment-list',
	    'gallery',
	    'caption',
	  ) );

    /* Custom Logo */
    add_theme_support( 'custom-logo', array(    	
    	'header-text' => array( 'site-title', 'site-description' ),
    ) );

    add_theme_support( 'custom-background' );

    if ( ! isset( $content_width ) ) $content_width = 900;
}

/** Theme setup **/
add_action( 'after_setup_theme', 'educrap_theme_setup');

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function educrap_content_width() {
	// This variable is intended to be overruled from themes.
	// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$GLOBALS['content_width'] = apply_filters( 'educrap_content_width', 640 );
}
add_action( 'after_setup_theme', 'educrap_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function educrap_widgets_init() {

    /*sidebar*/
    register_sidebar( array(
        'name' => esc_html__( 'Sidebar', 'educrap' ),
        'id' => 'sidebar-primary',
        'description' => esc_html__( 'The primary widget area', 'educrap' ),
        'before_widget' => '<div id="%1$s" class="%2$s">',
	    'after_widget' => '</div>',
	    'before_title' => '<h3 class="title">',
	    'after_title' => '</h3>',
    ) );

	register_sidebar( array(
	    'name' => esc_html__( 'Footer Widgets 1', 'educrap' ),
	    'id' => 'footer-widget-area-1',
	    'description' => esc_html__( 'footer widget area', 'educrap' ),
	    'before_widget' => '<div id="%1$s" class="footer__widget mb-50">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="footer__widget-title footer__widget-title-2">',
		'after_title' => '</h3>',
	) ); 

    register_sidebar( array(
        'name' => esc_html__( 'Footer Widgets 2', 'educrap' ),
        'id' => 'footer-widget-area-2',
        'description' => esc_html__( 'footer widget area', 'educrap' ),
        'before_widget' => '<div id="%1$s" class="footer__widget mb-50">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="footer__widget-title footer__widget-title-2">',
        'after_title' => '</h3>',
    ) ); 
    register_sidebar( array(
        'name' => esc_html__( 'Footer Widgets 3', 'educrap' ),
        'id' => 'footer-widget-area-3',
        'description' => esc_html__( 'footer widget area', 'educrap' ),
        'before_widget' => '<div id="%1$s" class="footer__widget mb-50">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="footer__widget-title footer__widget-title-2">',
        'after_title' => '</h3>',
    ) ); 
	register_sidebar( array(
	    'name' => esc_html__( 'Footer Widgets 4', 'educrap' ),
	    'id' => 'footer-widget-area-4',
	    'description' => esc_html__( 'footer widget area', 'educrap' ),
	    'before_widget' => '<div id="%1$s" class="footer__widget mb-50">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="footer__widget-title footer__widget-title-2">',
		'after_title' => '</h3>',
	) ); 
}

/** Theme **/
add_action( 'widgets_init', 'educrap_widgets_init' );

function educrap_fonts_url() {
    $fonts_url = '';

    $font_families = array();

    $font_families[] = 'Hind:wght@300;400;500;600;700';

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

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

    return esc_url_raw( $fonts_url );
}

/**
 * Enqueue scripts and styles.
*/
function educrap_scripts() {

    wp_enqueue_style( 'educrap-font', educrap_fonts_url(), array(), null );

    wp_enqueue_style( 'educrap-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.css');

    wp_enqueue_style( 'educrap-font-awesome', get_template_directory_uri(). '/assets/css/fontAwesome5Pro.css' );
    wp_enqueue_style( 'slicknav',   get_template_directory_uri() . '/assets/css/slicknav.css' );
    wp_enqueue_style( 'slick',   get_template_directory_uri() . '/assets/css/slick.css' );
    wp_enqueue_style( 'slicktheme',   get_template_directory_uri() . '/assets/css/slick-theme.css' );

    wp_enqueue_style( 'educrap-default-style', get_template_directory_uri() . '/assets/css/default.css');
    wp_enqueue_style( 'educrap-custom-style', get_template_directory_uri() . '/assets/css/custom-style.css');

    wp_enqueue_style( 'educrap-style', get_stylesheet_uri() );

    wp_enqueue_script( 'educrap-bootstrap-js', get_template_directory_uri() .'/assets/js/bootstrap.bundle.js', array( 'jquery' ), true, true);    
    wp_enqueue_script( 'jquery-slicknav',  get_template_directory_uri() . '/assets/js/jquery.slicknav.js', array( 'jquery' ), true, true); 
    wp_enqueue_script( 'slick-js',         get_template_directory_uri() . '/assets/js/slick.js', array( 'jquery' ), true, true);

    wp_enqueue_script( 'educrap-custom-script', get_template_directory_uri() . '/assets/js/custom.js', array( 'jquery' ), true, true); 

    wp_enqueue_script( 'educrap-navigation', get_template_directory_uri() . '/assets/js/navigation.js',array( 'jquery' ), true, true);  

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'educrap_scripts' );