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

if ( ! function_exists( 'kathmag_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 kathmag_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Kathmag, use a find and replace
		 * to change 'kathmag' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'kathmag', 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' );
		add_image_size( 'kathmag-thumbnail-0', 780, 520, true ); // Large Thumbnail
		add_image_size( 'kathmag-thumbnail-1', 640, 426, true ); // Featured Post 2, 
		add_image_size( 'kathmag-thumbnail-2', 500, 335, true ); // Small|Medium Thumbnail 
		add_image_size( 'kathmag-thumbnail-3', 400, 600, true ); // Long Thumbnail
		add_image_size( 'kathmag-thumbnail-4', 400, 400, true ); // Author
		add_image_size( 'kathmag-thumbnail-5', 600, 400, true ); // Big News Block Thumbnail

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'menu-1' => esc_html__( 'Primary', 'kathmag' ),
			'menu-2' => esc_html__( 'Top Menu', 'kathmag' ),
			'menu-3' => esc_html__( 'Footer', 'kathmag' ),
		) );

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

		// Set up the WordPress core custom background feature.
		add_theme_support( 'custom-background', apply_filters( 'kathmag_custom_background_args', array(
			'default-color' => 'ffffff',
			'default-image' => '',
		) ) );

		// 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 theme support for post-formats
		add_theme_support( 'post-formats', array( 'gallery', 'audio', 'video' ) );
	}
endif;
add_action( 'after_setup_theme', 'kathmag_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 kathmag_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( 'kathmag_content_width', 640 );
}
add_action( 'after_setup_theme', 'kathmag_content_width', 0 );

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

	// Sidebar Registration

	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar Widget Area', 'kathmag' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Add widgets here.', 'kathmag' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<div class="widget_title"><h3>',
		'after_title'   => '</h3></div>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Header Advertisement', 'kathmag' ),
		'id'            => 'advt-1',
		'description'   => esc_html__( 'Add Advertisement Here', 'kathmag' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '',
		'after_title'   => '',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Widget Area Left', 'kathmag' ),
		'id'            => 'footer-1',
		'description'   => esc_html__( 'Add Wigets Here', 'kathmag' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<div class="widget_title"><h3>',
		'after_title'   => '</h3></div>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Widget Area Middle', 'kathmag' ),
		'id'            => 'footer-2',
		'description'   => esc_html__( 'Add Wigets Here', 'kathmag' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<div class="widget_title"><h3>',
		'after_title'   => '</h3></div>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Widget Area Right', 'kathmag' ),
		'id'            => 'footer-3',
		'description'   => esc_html__( 'Add Wigets Here', 'kathmag' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<div class="widget_title"><h3>',
		'after_title'   => '</h3></div>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Advertisement Widget Area One', 'kathmag' ),
		'id'            => 'advertisement-1',
		'description'   => esc_html__( 'Add Advertisement Here', 'kathmag' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '',
		'after_title'   => '',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Advertisement Widget Area Two', 'kathmag' ),
		'id'            => 'advertisement-2',
		'description'   => esc_html__( 'Add Advertisement Here', 'kathmag' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '',
		'after_title'   => '',
	) );
}
add_action( 'widgets_init', 'kathmag_widgets_init' );

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

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

	wp_enqueue_style( 'kathmag-fonts', kathmag_fonts_url() );

	wp_enqueue_style( 'kathmag-main-style', get_template_directory_uri() . '/sparklewpthemes/assets/dist/css/main__style.min.css'  );

	wp_enqueue_script( 'kathmag-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20180319', true );

	wp_enqueue_script( 'kathmag-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20180319', true );

	wp_enqueue_script( 'kathmag-bundle', get_template_directory_uri() . '/sparklewpthemes/assets/dist/js/bundle.min.js', array( 'jquery','masonry'), '20180319', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {

		wp_enqueue_script( 'comment-reply' );

	}
}
add_action( 'wp_enqueue_scripts', 'kathmag_scripts' );


/**
 * Require init.
*/
require  trailingslashit( get_template_directory() ).'sparklewpthemes/init.php';

