<?php
/**
 * Theme bootstrap functions.
 *
 * @package Journal Book
 */

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

if ( ! defined( 'JOURNAL_BOOK_VERSION' ) ) {
	// Replace the version number of the theme on each release.
	define( 'JOURNAL_BOOK_VERSION', '1.0.0' );
}

if ( ! function_exists( 'journal_book_asset_url' ) ) {
	/**
	 * Return Journal Book theme folder asset url
	 * 
	 * @param mixed $path
	 * @return string
	 */
	function journal_book_asset_url( $path ) {
		return trailingslashit( get_stylesheet_directory_uri() ) . 'assets/' . $path;
	}

}

if ( ! function_exists( 'journal_book_the_asset_url' ) ) {
	/**
	 * Echo Journal Book theme folder asset url
	 * 
	 * @param mixed $path
	 * @return void
	 */
	function journal_book_the_asset_url( $path ) {
		echo esc_url( journal_book_asset_url( $path ) );
	}

}

if ( ! function_exists( 'journal_book_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.
	 *
	 * @return void
	 * @since 1.0.0
	 *
	 */
	function journal_book_setup() {

		// Make theme available for translation.
		load_child_theme_textdomain( 'journal-book', get_stylesheet_directory() . '/languages' );

		// Remove core block patterns.
		remove_theme_support( 'core-block-patterns' );

	}
}
add_action( 'after_setup_theme', 'journal_book_setup' );

if ( ! function_exists( 'journal_book_register_block_pattern_category' ) ) {
	/**
	 * Register Journal Book pattern category
	 * 
	 * @return void
	 */
	function journal_book_register_block_pattern_category() {
		if ( function_exists( 'register_block_pattern_category' ) ) {
			register_block_pattern_category( 'journal-book', array(
				'label' => __( 'Journal Book Theme', 'journal-book' )
			) );
		}
	}

}

add_action( 'init', 'journal_book_register_block_pattern_category' );

//
// Theme SVG icons
//
if ( ! function_exists( 'journal_book_svg_icons' ) ) {
	function journal_book_svg_icons( $icons ) {
		$icons[] = array(
			'name' => __( 'asterisk', 'journal-book' ),
			'slug' => 'asterisk',
			'svg'  => '<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" viewBox="0 0 512 512"><g><path d="M480.9 226.8h-148l104.6-104.7c12.3-12 12.6-31.7.6-44s-31.7-12.6-43.9-.6l-.6.6-104.7 104.8V31.1c.3-17.2-13.4-31.3-30.5-31.6-17.2-.3-31.3 13.4-31.6 30.5v152.9L119.5 75.5c-12.1-12.1-31.8-12.1-43.9 0s-12.1 31.8 0 43.9l107.3 107.3H31.1c-17.2-.3-31.3 13.4-31.6 30.5s13.4 31.3 30.5 31.6h152.9L75.5 396.3c-12.1 12.1-12.1 31.8 0 43.9s31.8 12.1 43.9 0l107.3-107.3v148c-.3 17.2 13.4 31.3 30.5 31.6s31.3-13.4 31.6-30.5V332.9l104.7 104.7c12 12.3 31.7 12.6 44 .6s12.6-31.7.6-44l-.6-.6-104.6-104.7h148c17.2.3 31.3-13.4 31.6-30.5.3-17.2-13.4-31.3-30.5-31.6h-1.1z"></path></g></svg>',
			'tags' => [ 'asterisk' ],
		);

		return $icons;
	}
}
add_filter( 'plover_core_icon_collection', 'journal_book_svg_icons' );

//
// Theme dashboard hook
//
if ( ! function_exists( 'journal_book_theme_screenshot' ) ) {
	function journal_book_theme_screenshot() {
		return trailingslashit( get_stylesheet_directory_uri() ) . 'screenshot.png';
	}

}
add_filter( 'plover_welcome_theme_screenshot', 'journal_book_theme_screenshot' );

if ( ! function_exists( 'journal_book_support_forum_url' ) ) {
	function journal_book_support_forum_url() {
		return 'https://wordpress.org/support/theme/journal-book/';
	}

}
add_filter( 'plover_theme_support_forum_url', 'journal_book_support_forum_url' );

if ( ! function_exists( 'journal_book_rate_us_url' ) ) {
	function journal_book_rate_us_url() {
		return 'https://wordpress.org/support/theme/journal-book/reviews/?rate=5#new-post';
	}

}
add_filter( 'plover_theme_rate_us_url', 'journal_book_rate_us_url' );

if ( ! function_exists( 'journal_book_default_color_mode' ) ) {
	function journal_book_default_color_mode() {
		return 'system';
	}
}
add_filter( 'plover_theme_default_color_mode', 'journal_book_default_color_mode' );

if ( ! function_exists( 'journal_book_enqueue_main_style' ) ) {
	function journal_book_enqueue_main_style() {
		wp_enqueue_style( 'journal-book-style', get_stylesheet_uri(), array(), JOURNAL_BOOK_VERSION );
	}
}
add_action( 'wp_enqueue_scripts', 'journal_book_enqueue_main_style' );
add_action( 'enqueue_block_assets', 'journal_book_enqueue_main_style' );


if ( ! function_exists( 'journal_book_register_block_styles' ) ) {
	/**
	 * Register theme block styles
	 * 
	 * @return void
	 */
	function journal_book_register_block_styles() {
		register_block_style( 'core/paragraph', [
			'name'  => 'outline',
			'label' => __( 'Outline', 'journal-book' ),
		] );
		register_block_style( 'core/heading', [
			'name'  => 'outline',
			'label' => __( 'Outline', 'journal-book' ),
		] );
	}
}
add_action( 'init', 'journal_book_register_block_styles' );
