<?php
add_action( 'enqueue_block_editor_assets', 'kingcabs_extend_block_enqueue_block_editor_assets' );

function kingcabs_extend_block_enqueue_block_editor_assets() {
	// Enqueue our script
    wp_enqueue_script(
        'extend-block-example-js',
        esc_url( get_template_directory_uri( ).'/dist/extend-blocks.js' ),
        array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor' ),
        '1.0.0',
        true // Enqueue the script in the footer.
    );
}


add_action( 'wp_enqueue_scripts', 'edcuenter_block_extend_enqueue_scripts', 10 );
/**
 * Register proxy handle for inline frontend scripts.
 *
 * Called in styles.php to share page content string.
 *
 * @since 0.0.27
 *
 * @return void
 */
function kingcabs_reduce_whitespace( string $string ): string {
	return preg_replace( '/\s+/', ' ', $string );
}
function edcuenter_block_extend_enqueue_scripts(): void {
	
	$handle = get_template();
	wp_enqueue_script( 'jquery');
	wp_register_script(
		$handle,
		'',
		[],
		wp_get_theme()->get( 'version' ),
		true
	);

	wp_add_inline_script(
		$handle,
		kingcabs_reduce_whitespace(
			trim(
				apply_filters(
					'kingcabs_block_inline_js',
					'',
					(string) ( $GLOBALS['template_html'] ?? '' )
				)
			)
		)
	);

	wp_enqueue_script( $handle );


	/** enquue styles */

	wp_register_style(
		$handle,
		'',
		[],
		wp_get_theme()->get( 'Version' )
	);

	wp_enqueue_style( $handle );

	wp_add_inline_style(
		$handle,
		kingcabs_reduce_whitespace(
			trim(
				apply_filters(
					'kingcabs_block_inline_css',
					'',
					(string) ( $GLOBALS['template_html'] ?? '' )
				)
			)
		)
	);
}



/**
 * Registers an editor stylesheet for the current theme.
 */
function kingcabs_block_add_editor_styles() {
    $font_url = str_replace( ',', '%2C', 'https://fonts.googleapis.com/icon?family=Material+Icons' );
    add_editor_style( $font_url );
	
	add_editor_style(get_template_directory_uri() . '/blocks-extends/assets/css/editor-style.css');
}
add_action( 'admin_init', 'kingcabs_block_add_editor_styles', 100 );

/**
 * Enqueue a script in the WordPress admin on edit.php.
 *
 * @param int $hook Hook suffix for the current admin page.
 */
function kingcabs_block_enqueue_admin_script( $hook ) {
    if ( 'post.php' != $hook ) {
        return;
    }

	$font_url = str_replace( ',', '%2C', 'https://fonts.googleapis.com/icon?family=Material+Icons' );
	wp_enqueue_style( 'googlefonts-material-icon', $font_url, array(), null );


    wp_enqueue_style( $font_url );
}
add_action( 'admin_enqueue_scripts', 'kingcabs_block_enqueue_admin_script' );



require_once __DIR__ . "/utility/dom.php";
require_once __DIR__ . "/blocks/counter.php";
require_once __DIR__ . "/blocks/icon.php";
require_once __DIR__ . "/blocks/progressbar.php";
require_once __DIR__ . "/blocks/position.php";