<?php
define( 'MONOCLE_VERSION', wp_get_theme()->get( 'Version' ) );
define( 'MONOCLE_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true );
define( 'MONOCLE_DIR', trailingslashit( get_template_directory() ) );
define( 'MONOCLE_URL', trailingslashit( get_template_directory_uri() ) );

if ( ! function_exists( 'monocle_support' ) ) :

	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * @since monocle 1.0.0
	 *
	 * @return void
	 */
	function monocle_support() {
		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );
		// Add support for block styles.
		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'post-thumbnails' );
		// Enqueue editor styles.
		add_editor_style( 'style.css' );
		// Removing default patterns.
		remove_theme_support( 'core-block-patterns' );
	}

endif;
add_action( 'after_setup_theme', 'monocle_support' );

/*
----------------------------------------------------------------------------------
Enqueue Styles
-----------------------------------------------------------------------------------*/
if ( ! function_exists( 'monocle_styles' ) ) :
	function monocle_styles() {
		// registering style for theme
		wp_enqueue_style( 'monocle-style', get_stylesheet_uri(), array(), MONOCLE_VERSION );
		if ( is_rtl() ) {
			wp_enqueue_style( 'monocle-rtl-css', get_template_directory_uri() . '/assets/css/rtl.css', 'rtl_css', MONOCLE_VERSION );
		}
	}
endif;

add_action( 'wp_enqueue_scripts', 'monocle_styles' );

/**
 * Enqueue assets scripts for both backend and frontend
 */
add_action(
	'enqueue_block_assets',
	function () {
		wp_enqueue_style( 'monocle-blocks-style', get_template_directory_uri() . '/assets/css/blocks.css', array(), MONOCLE_VERSION );
	}
);

/**
 * Load core file.
 */
require_once get_template_directory() . '/inc/core/init.php';

function monocle_add_woocommerce_support() {
	add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'monocle_add_woocommerce_support' );

function monocle_premium_access() {
	$status = false;

	if ( function_exists( 'cozy_addons_premium_access' ) ) {
		$status = cozy_addons_premium_access();
	}

	return $status;
}

function monocle_is_plugin_installed( $plugin_slug ) {
	$plugin_path = WP_PLUGIN_DIR . '/' . $plugin_slug;
	return file_exists( $plugin_path );
}
function monocle_is_plugin_activated( $plugin_slug ) {
	return is_plugin_active( $plugin_slug );
}

/* Admin init */
if ( is_admin() ) {
	require_once MONOCLE_DIR . 'admin/class-admin.php';
	Monocle_Admin::get_instance();
}