<?php
/**
 * Matchday functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package   Matchday
 * @since     1.0.0
 * @version   1.1.0
 */

if (!defined('MATCHDAY_VERSION')) {
	/*
	 * Set the theme’s version number.
	 *
	 * This is used primarily for cache busting.
	 */
	define('MATCHDAY_VERSION', '1.1.0');
}

if (!function_exists('matchday_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 matchday_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Matchday, use a find and replace
		 * to change 'matchday' to the name of your theme in all the template files.
		 */
		load_theme_textdomain('matchday', get_template_directory() . '/languages');

		/*
		 * 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');

		// Register custom image sizes.
		add_image_size('matchday-medium', 450, 468);
		add_image_size('matchday-large', 900, 936);

		// Add support for editor styles.
		add_theme_support('editor-styles');

		// Enqueue editor styles.
		add_editor_style('style-editor.css');
		add_editor_style('style-editor-extra.css');
	}
endif;
add_action('after_setup_theme', 'matchday_setup');

/**
 * Enqueue scripts and styles.
 */
function matchday_scripts() {
	// Enqueue scripts
	wp_enqueue_script(
		'matchday-script',
		get_template_directory_uri() . '/js/script.min.js',
		[],
		MATCHDAY_VERSION,
		true,
	);
}
add_action('wp_enqueue_scripts', 'matchday_scripts');

/**
 * Enqueue styles.
 * We need to enqueue it early before the global-styles-inline-css is outputed
 * becuase TailwindCSS has CSS reset effects on the WordPress styles created with theme.json
 */
function matchday_styles() {
	// Register styles
	wp_register_style(
		'matchday-style',
		get_stylesheet_uri(),
		[],
		MATCHDAY_VERSION,
	);

	// Enqueue styles
	wp_enqueue_style('matchday-style');
}
add_action('wp_enqueue_scripts', 'matchday_styles');

/**
 * Enqueue the block editor script.
 */
function matchday_enqueue_block_editor_script() {
	if (is_admin()) {
		wp_enqueue_script(
			'matchday-editor',
			get_template_directory_uri() . '/js/block-editor.min.js',
			['wp-blocks', 'wp-edit-post'],
			MATCHDAY_VERSION,
			true,
		);
	}
}
add_action('enqueue_block_assets', 'matchday_enqueue_block_editor_script');

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

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

/**
 * Theme icons for the core Icon block (WordPress 7.1+).
 */
require get_template_directory() . '/inc/icons.php';

/**
 * Add plugins suggestion
 */
require_once get_template_directory() .
	'/inc/tgm/class-tgm-plugin-activation.php';
require_once get_template_directory() . '/inc/tgm/tgm-init.php';
