<?php
/**
 * Blogin Aarambha functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Blogin_Aarambha
 */

/**
 * Blogin Aarambha only works in WordPress 5.6 or later.
 */
if ( version_compare( $GLOBALS['wp_version'], '5.6', '<' ) ) {
	require get_template_directory() . '/inc/back-compat.php';
	return;
}

/**
 * Define Constants
 */
if ( ! defined( 'BLOGIN_AARAMBHA_VERSION' ) ) {
	// Replace the version number of the theme on each release.
	define( 'BLOGIN_AARAMBHA_VERSION', '1.0.1' );
}
if ( ! defined( 'BLOGIN_AARAMBHA_DIR' ) ) {
	define( 'BLOGIN_AARAMBHA_DIR', trailingslashit( get_template_directory() ) );
}
if ( ! defined( 'BLOGIN_AARAMBHA_URI' ) ) {
	define( 'BLOGIN_AARAMBHA_URI', trailingslashit( esc_url( get_template_directory_uri() ) ) );
}
if ( ! defined( 'BLOGIN_AARAMBHA_SCRIPT_PREFIX' ) ) {
	define( 'BLOGIN_AARAMBHA_SCRIPT_PREFIX', ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min' );
}

if ( ! function_exists( 'blogin_aarambha_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function blogin_aarambha_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Blogin Aarambha, use a find and replace
		 * to change 'blogin-aarambha' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'blogin-aarambha', get_template_directory() . '/languages' );

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

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );

		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support( 'post-thumbnails' );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus(
			array(
				'primary-menu' => esc_html__( 'Primary Menu', 'blogin-aarambha' ),
				'mobile-menu'  => esc_html__( 'Mobile Menu', 'blogin-aarambha' ),
				'footer-menu'  => esc_html__( 'Footer Menu', 'blogin-aarambha' ),
			)
		);

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support(
			'html5',
			array(
				'search-form',
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
				'style',
				'script',
			)
		);

		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support(
			'custom-logo',
			array(
				'height'      => 250,
				'width'       => 250,
				'flex-width'  => true,
				'flex-height' => true,
			)
		);

		// Add support for page excerpt
		add_post_type_support( 'page', 'excerpt' );

		// Add support for Block Styles.
		add_theme_support( 'wp-block-styles' );

		// Add support for full and wide align images.
		add_theme_support( 'align-wide' );

		// Add support for responsive embedded content.
		add_theme_support( 'responsive-embeds' );
	}
endif;
add_action( 'after_setup_theme', 'blogin_aarambha_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 blogin_aarambha_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'blogin_aarambha_content_width', 640 );
}
add_action( 'after_setup_theme', 'blogin_aarambha_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function blogin_aarambha_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'blogin-aarambha' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'blogin-aarambha' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	// Widget Sidebar
	for ( $sidebar = 1; $sidebar <= 6; $sidebar++ ) {
		register_sidebar(
			array(
				'name'          => sprintf( esc_html__( 'Footer Sidebar %d ', 'blogin-aarambha' ), absint( $sidebar ) ),
				'id'            => 'footer-sidebar-' . absint( $sidebar ),
				'description'   => esc_html__( 'Display widgets footer section of the site.', 'blogin-aarambha' ),
				'before_widget' => '<section id="%1$s" class="widget %2$s">',
				'after_widget'  => '</section>',
				'before_title'  => '<h2 class="widget-title">',
				'after_title'   => '</h2>',
			)
		);
	}
}
add_action( 'widgets_init', 'blogin_aarambha_widgets_init' );

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

	// Font Awesome Style
	wp_enqueue_style( 'fontawesome', BLOGIN_AARAMBHA_URI . 'assets/css/all.min.css' );

	// MeanMenu Style
	wp_enqueue_style( 'meanmenu', BLOGIN_AARAMBHA_URI . 'assets/css/meanmenu' . BLOGIN_AARAMBHA_SCRIPT_PREFIX . '.css', array(), '2.0.7' );

	// Theme Style
	wp_enqueue_style( 'blogin-aarambha-style', get_stylesheet_uri(), array(), BLOGIN_AARAMBHA_VERSION );

	// Main Style
	wp_enqueue_style( 'blogin-aarambha-main', BLOGIN_AARAMBHA_URI . 'assets/css/styles' . BLOGIN_AARAMBHA_SCRIPT_PREFIX . '.css', null, BLOGIN_AARAMBHA_VERSION, 'all' );

	// Responsive Style
	wp_enqueue_style( 'blogin-aarambha-responsive', BLOGIN_AARAMBHA_URI . 'assets/css/responsive' . BLOGIN_AARAMBHA_SCRIPT_PREFIX . '.css', null, BLOGIN_AARAMBHA_VERSION, 'all' );

	// Theme inline style
	wp_add_inline_style( 'blogin-aarambha-main', Blogin_Aarambha_Customizer_Inline_Style::css_output( 'front-end' ) );

	// Editor inline style
	wp_add_inline_style( 'blogin-aarambha-main', Blogin_Aarambha_Customizer_Inline_Style::css_output( 'editor' ) );

	// Enqueue MeanMenu Js
	wp_enqueue_script( 'meanmenu', BLOGIN_AARAMBHA_URI . 'assets/js/jquery.meanmenu' . BLOGIN_AARAMBHA_SCRIPT_PREFIX . '.js', array( 'jquery' ), '2.0.7', true );

	// Enqueue theia-sticky-sidebar Js
	$sticky_sidebar = get_theme_mod( 'blogin_aarambha_sidebar_sticky', '' );
	if ( $sticky_sidebar ) {
		wp_enqueue_script( 'theia-sticky-sidebar', BLOGIN_AARAMBHA_URI . 'assets/js/theia-sticky-sidebar' . BLOGIN_AARAMBHA_SCRIPT_PREFIX . '.js', array( 'jquery' ), '1.7.0', true );
	}

	// Main scripts.
	wp_enqueue_script( 'blogin-aarambha-script', BLOGIN_AARAMBHA_URI . 'assets/js/script' . BLOGIN_AARAMBHA_SCRIPT_PREFIX . '.js', array( 'jquery' ), BLOGIN_AARAMBHA_VERSION, true );

	// Localized Data
    wp_localize_script( 
		'blogin-aarambha-script', 
		'BLOGIN_AARAMBHA',
		array(
			'sticky_sidebar'  => ( $sticky_sidebar ) ? true : false
		)
	);


	// Comment Reply
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'blogin_aarambha_scripts' );

/**
 * Custom template tags for this theme.
 */
require BLOGIN_AARAMBHA_DIR . 'inc/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require BLOGIN_AARAMBHA_DIR . 'inc/template-functions.php';

/**
 * Google fonts utilities
 */
require BLOGIN_AARAMBHA_DIR . 'inc/classes/Blogin_Aarambha_Google_Fonts.php';

/**
 * Font Awesome Icon
 */
require BLOGIN_AARAMBHA_DIR . 'inc/classes/Blogin_Aarambha_Font_Awesome_Icons.php';

/**
 * Breadcrumb
 */
require BLOGIN_AARAMBHA_DIR . 'inc/classes/Blogin_Aarambha_Breadcrumb.php';

/**
 * Helper Functions
 */
require BLOGIN_AARAMBHA_DIR . 'inc/classes/Blogin_Aarambha_Helper.php';

/**
 * Customizer additions.
 */
require BLOGIN_AARAMBHA_DIR . 'inc/customizer/Blogin_Aarambha_Customizer.php';

// Builder
require BLOGIN_AARAMBHA_DIR . 'inc/customizer/builder/Blogin_Aarambha_Customizer_Builder.php';
require BLOGIN_AARAMBHA_DIR . 'inc/customizer/builder/header/Blogin_Aarambha_Customizer_Header_Builder.php';
require BLOGIN_AARAMBHA_DIR . 'inc/customizer/builder/footer/Blogin_Aarambha_Customizer_Footer_Builder.php';

/**
 * Load theme meta box
 */
require BLOGIN_AARAMBHA_DIR . 'inc/meta-boxes/Blogin_Aarambha_Meta_Boxes.php';


/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require BLOGIN_AARAMBHA_DIR . 'inc/compatibility/jetpack/jetpack.php';
}

/**
 * Load WooCommerce compatibility file.
 */
if ( class_exists( 'WooCommerce' ) ) {
	require BLOGIN_AARAMBHA_DIR . 'inc/compatibility/woocommerce/woocommerce.php';
}

/**
 * Load hooks file.
 */
require BLOGIN_AARAMBHA_DIR . 'inc/hooks/hooks.php';
require BLOGIN_AARAMBHA_DIR . 'inc/hooks/functions.php';

/**
 * Load plugin recommendations.
 */
require BLOGIN_AARAMBHA_DIR . 'inc/tgm/tgm.php';

/**
 * Gutenberg editor
 */
require BLOGIN_AARAMBHA_DIR . 'inc/Blogin_Aarambha_Editor_Style.php';
