<?php
/**
 * Loading all css & js files.
 *
 * @link https://developer.wordpress.org/themes/basics/including-css-javascript/
 *
 * The template loading under functions.php
 *
 * @package RB_Themes
 * @subpackage RB_Blog_Two
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/*
==================================
Table of Theme Assets List Start Here
=====================================
	01. Prefix with file directory
	02. Google Fonts
	03. Custom Assets
	04. WordPress Assets
*/

define( 'RB_BLOG_TWO_URL', get_template_directory_uri() );
define( 'RB_BLOG_TWO_CSS', RB_BLOG_TWO_URL . '/assets/css/' );
define( 'RB_BLOG_TWO_JS', RB_BLOG_TWO_URL . '/assets/js/' );

/**
 * Google Fonts.
 */
add_editor_style( array( rb_blog_two_google_fonts() ) );

/**
 * Register Google fonts.
 */
function rb_blog_two_google_fonts() {
	$fonts_url       = '';
	$font_families   = array();
	$font_families[] = 'Josefin Sans:300';
	$font_families[] = 'Josefin Sans:600';
	$query_args      = array(
		'family' => rawurlencode( implode( '|', $font_families ) ),
	);
	$fonts_url       = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
	return esc_url_raw( $fonts_url );
}

/**
 * Register Google fonts CSS.
 */
function rb_blog_two_google_font_css() {
	// Google Font.
	wp_enqueue_style( 'rb-blog-two-google-font', rb_blog_two_google_fonts(), '', wp_get_theme()->get( 'Version' ), 'all' );
}
add_action( 'wp_enqueue_scripts', 'rb_blog_two_google_font_css' );

/**
 * Custom Assets.
 */
function rb_blog_two_theme_custom_assets() {
	// Default CSS.
	wp_enqueue_style( 'rb-blog-two-default', RB_BLOG_TWO_CSS . 'default.css', '', time(), 'all' );

	// Theme Style CSS.
	wp_enqueue_style( 'rb-blog-two-style', RB_BLOG_TWO_CSS . 'style.css', '', time(), 'all' );

	// Responsive CSS.
	wp_enqueue_style( 'rb-blog-two-responsive', RB_BLOG_TWO_CSS . 'responsive.css', '', time(), 'all' );

	// Theme Custom JS.
	wp_enqueue_script( 'rb-blog-two-custom', RB_BLOG_TWO_JS . 'custom.js', array( 'jquery' ), time(), true );
}
add_action( 'wp_enqueue_scripts', 'rb_blog_two_theme_custom_assets' );

/**
 * WordPress Assets.
 */
function rb_blog_two_wp_assets() {
	// WP Required Style.
	wp_enqueue_style( 'rb-blog-two-wp-style', get_stylesheet_uri(), '', time(), 'all' );

	// Threaded comment reply styles.
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'rb_blog_two_wp_assets' );

/**
 * Register custom block styles
 */
if ( ! function_exists( 'rb_blog_two_register_block_styles' ) ) {
	/**
	 * Register custom block styles.
	 */
	function rb_blog_two_register_block_styles() {
		register_block_style(
			'core/button',
			array(
				'name'  => 'rb-blog-two-button',
				'label' => esc_html__( 'RB Blog Two Button', 'rb-blog-two' ),
			)
		);
	}
	add_action( 'init', 'rb_blog_two_register_block_styles' );
}

/**
 * Register custom block patterns
 */
if ( ! function_exists( 'rb_blog_two_register_block_patterns' ) ) {
	/**
	 * Register custom block patterns.
	 */
	function rb_blog_two_register_block_patterns() {
		register_block_pattern(
			'rb-blog-two/button',
			array(
				'title'       => __( 'RB Blog Two Button', 'rb-blog-two' ),
				'description' => __( 'A simple button block.', 'rb-blog-two' ),
				'content'     => '
					<!-- wp:buttons -->
					<div class="wp-block-buttons">
						<!-- wp:button {"className":"is-style-rb-blog-two-button"} -->
						<div class="wp-block-button is-style-rb-blog-two-button">
							<a class="wp-block-button__link" href="#">Click Here</a>
						</div>
						<!-- /wp:button -->
					</div>
					<!-- /wp:buttons -->
				',
			)
		);
	}
	add_action( 'init', 'rb_blog_two_register_block_patterns' );
}
