<?php
/**
 * Blocks Setup
 * This file is loaded using 'after_setup_theme' hook at priority 10
 */

/* === WordPress Blocks === */

/** Add Gutenberg Wide Align support **/
add_theme_support( 'align-wide' );

/** Add slightly more opinionated styles for the front end **/
add_theme_support( 'wp-block-styles' );

/** Support custom line heights for paragraphs and headings **/
add_theme_support( 'custom-line-height' );

/** Custom spacing option for blocks like cover and group **/
add_theme_support( 'custom-spacing' );

/** Responsive embedded content **/
add_theme_support( 'responsive-embeds' );
/** Remove custom background support - instead use colors in theme.json **/
remove_theme_support( 'custom-background' );


/**
 * Color Pallete
 * Add accent colors to Block Pallete
 */
if ( apply_filters( 'hoot_editor_color_palette', true ) )
	add_action( 'init', 'hoot_wpblock_color_palette' );
if ( ! function_exists( 'hoot_wpblock_color_palette' ) ) :
function hoot_wpblock_color_palette() {
	$palette = array();
	$defaults = array(
		'#000000' => array( 'black',                 __( 'Black', 'olius' ) ),
		'#abb8c3' => array( 'cyan-bluish-gray',      __( 'Cyan bluish gray', 'olius' ) ),
		'#ffffff' => array( 'white',                 __( 'White', 'olius' ) ),
		'#f78da7' => array( 'pale-pink',             __( 'Pale pink', 'olius' ) ),
		'#cf2e2e' => array( 'vivid-red',             __( 'Vivid red', 'olius' ) ),
		'#ff6900' => array( 'luminous-vivid-orange', __( 'Luminous vivid orange', 'olius' ) ),
		'#fcb900' => array( 'luminous-vivid-amber',  __( 'Luminous vivid amber', 'olius' ) ),
		'#7bdcb5' => array( 'light-green-cyan',      __( 'Light green cyan', 'olius' ) ),
		'#00d084' => array( 'vivid-green-cyan',      __( 'Vivid green cyan', 'olius' ) ),
		'#8ed1fc' => array( 'pale-cyan-blue',        __( 'Pale cyan blue', 'olius' ) ),
		'#0693e3' => array( 'vivid-cyan-blue',       __( 'Vivid cyan blue', 'olius' ) ),
		'#9b51e0' => array( 'vivid-purple',          __( 'Vivid purple', 'olius' ) ),
	);
	if ( apply_filters( 'hoot_editor_accents', true, 'palette' ) ) {
		$palette[] = array(
			'name' => __( 'Theme Accent Color', 'olius' ),
			'slug' => 'accent',
			'color' => hoot_get_mod( 'accent_color' ),
		);
		$palette[] = array(
			'name' => __( 'Theme Accent Font Color', 'olius' ),
			'slug' => 'accent-font',
			'color' => hoot_get_mod( 'accent_font' ),
		);
	}
	foreach ( $defaults as $key => $value ) {
		$palette[] = array( 'name' => $value[1], 'slug' => $value[0], 'color' => $key );
	}
	add_theme_support( 'editor-color-palette', $palette );
}
endif;


/**
 * Block Styles
 */

add_action( 'init', 'hoot_wpblock_styles' );
if ( ! function_exists( 'hoot_wpblock_styles' ) ) :
function hoot_wpblock_styles() {
	register_block_style( 'core/image', array(
		'name'  => 'hoot-image-border',
		'label' => esc_html__( 'Border', 'olius' ),
	) );
	register_block_style( 'core/image', array(
		'name'  => 'hoot-image-frame',
		'label' => esc_html__( 'Frame', 'olius' ),
	) );
	register_block_style( 'core/list', array(
		'name'  => 'hoot-checklist',
		'label' => __( 'Checkmark', 'olius' ),
		'inline_style' =>	'div ul.is-style-hoot-checklist { list-style-type: "\2713"; }' .
							'div ul.is-style-hoot-checklist li { padding-inline-start: 1ch; }',
	) );
	register_block_style( 'core/heading', array(
		'name'  => 'hoot-headblock1',
		'label' => __( 'Style 1', 'olius' ),
	) );
	register_block_style( 'core/heading', array(
		'name'  => 'hoot-headblock2',
		'label' => __( 'Style 2', 'olius' ),
	) );
	register_block_style( 'core/heading', array(
		'name'  => 'hoot-headblock3',
		'label' => __( 'Style 3', 'olius' ),
	) );
}
endif;



/**
 * Add Stylesheets
 */

// Load after main stylesheet (and hootkit if available), but before child theme's stylesheet (and child hootkit)
add_action( 'wp_enqueue_scripts', 'hoot_wpblock_assets', 16 );
if ( ! function_exists( 'hoot_wpblock_assets' ) ) :
function hoot_wpblock_assets(){
	$style_uri = hoot_locate_style( 'include/blocks/wpblocks' );
	wp_enqueue_style( 'hoot-wpblocks', $style_uri, array(), hoot_data()->template_version );
}
endif;

// Set dynamic css handle to hoot-wpblocks
add_filter( 'hoot_style_builder_inline_style_handle', 'hoot_wpblock_dynamic_css_handle', 4 );
if ( ! function_exists( 'hoot_wpblock_dynamic_css_handle' ) ) :
function hoot_wpblock_dynamic_css_handle(){ return 'hoot-wpblocks'; }
endif;
// Editor stylesheet (HBS loads @10)
add_action( 'enqueue_block_editor_assets', 'hoot_wpblock_editor_assets', 12 );
if ( ! function_exists( 'hoot_wpblock_editor_assets' ) ) :
function hoot_wpblock_editor_assets(){
	// This is loaded in only Backend...
	$style_uri = hoot_locate_style( 'include/blocks/wpblocks-editor' );
	wp_enqueue_style( 'hoot-wpblocks-editor', $style_uri, array(), hoot_data()->template_version );
}
endif;
// Editor stylesheet - This file is loaded using 'after_setup_theme' hook at priority 10
add_editor_style( 'include/admin/css/editor-style.css' );
