<?php

/**
 * Genolve Toolkit Ornate  Separator Block
 * Place ornate or animated separators with Gutenberg editor.
 */

defined( 'ABSPATH' ) || exit;

/**
 * Load all translations for our plugin from the MO file.
 */
add_action( 'init', 'genolve_toolkit_bseparator_load_textdomain' );

function genolve_toolkit_bseparator_load_textdomain() {
	load_plugin_textdomain( 'genolve-toolkit', false, basename( __DIR__ ) . '/languages' );
}

/**
 * Registers all block assets so that they can be enqueued through Gutenberg in
 * the corresponding context.
 *
 * Passes translations to JavaScript.
 */
function genolve_toolkit_bseparator_register_block() {

	if ( ! function_exists( 'register_block_type' ) ) {
		// Gutenberg is not active.
		return;
	}

	wp_register_script(
			'genolve-toolkit-bseparator',
			plugins_url( 'block.js', __FILE__ ),
			array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'underscore' ),
			filemtime( plugin_dir_path( __FILE__ ) . 'block.js' )
		);
  
	wp_localize_script( 'genolve-toolkit-bseparator', 'genolveToolkitBseparator', array(
		'pluginUrl' => plugin_dir_url( dirname( __FILE__ ) ),
	) );
	
	register_block_type( 'genolve-toolkit/bseparator', array(
			'editor_script' => 'genolve-toolkit-bseparator'
		//	,			'render_callback' => 'genolve_block_separator_render',
		) );

  if ( function_exists( 'wp_set_script_translations' ) ) {
    /**
     * May be extended to wp_set_script_translations( 'my-handle', 'my-domain',
     * plugin_dir_path( MY_PLUGIN ) . 'languages' ) ). For details see
     * https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
     */
    wp_set_script_translations( 'genolve-toolkit-bseparator', 'genolve-toolkit' );
  }

}
add_action( 'init', 'genolve_toolkit_bseparator_register_block' );

/** 
genolve_block_separator_render - render the separator block

reference here: https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/block-tutorial/creating-dynamic-blocks/

function genolve_block_separator_render( $attributes, $content ) {
    $thebg = get_option( 'genolve_block_separator' );
    if (  $thebg ==null ) {
        return 'No background selected';
    }
  	$theicon = '<!-- attributes:'.$attributes.'-->';
		$theicon .= '<div style="width:500px;height:20px;background-image:url(\''.$thebg.'\')"></div>';
    return $theicon;
}
*/

?>