<?php

/**
 * Genolve Toolkit AI Widget Block
 * AI image and video generation interface for resellers.
 */

defined( 'ABSPATH' ) || exit;

/**
 * Registers all block assets so that they can be enqueued through Gutenberg in
 * the corresponding context.
 */
function genolve_toolkit_bwidgetai_register_block() {

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

	wp_register_script(
			'genolve-toolkit-bwidgetai',
			plugins_url( 'block.js', __FILE__ ),
			array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ),
			filemtime( plugin_dir_path( __FILE__ ) . 'block.js' )
		);

	wp_localize_script( 'genolve-toolkit-bwidgetai', 'genolveToolkitBwidgetai', array(
		'pluginUrl' => plugin_dir_url( dirname( __FILE__ ) ),
	) );

	register_block_type( 'genolve-toolkit/bwidgetai', array(
			'editor_script'   => 'genolve-toolkit-bwidgetai',
			'render_callback' => 'genolve_toolkit_bwidgetai_render',
		) );

	if ( function_exists( 'wp_set_script_translations' ) ) {
		wp_set_script_translations( 'genolve-toolkit-bwidgetai', 'genolve-toolkit' );
	}

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

/**
 * Render callback for the AI widget block.
 */
function genolve_toolkit_bwidgetai_render( $attributes, $content ) {
	$myimg = plugins_url() . "/genolve-toolkit/img/spacer.gif";
	$retval =  '<div id="gnlv-aigen" class="twbs"><div id="stagecenter" class="gnlv-stagecommon gnlv-scrollbar"><div id="gnlv-tmpdiv">'
		. 'When published the AI generator widget will go here. This is for Genolve resellers and must first be activated in the Genolve dashboard &ndash; Reseller Options.'
		. '<img src="'.$myimg.'" onload="genolve_checkcustomize();" >'
		. '</div></div></div>';
	return $retval;
}

?>