<?php

/**
 * Enqueue block editor JavaScript and CSS
*/
add_action( 'enqueue_block_editor_assets', 'treethemes_editor_scripts' );
function treethemes_editor_scripts() {

	// Enqueue the bundled block JS file
	wp_enqueue_script(
		'treethemes-block',
		plugins_url( 'treethemes-block.js', __FILE__ ), 
		[ 'wp-blocks', 'wp-element', 'wp-components', 'wp-i18n' ], // dependencies
		filemtime( plugin_dir_path( __FILE__ ) . 'treethemes-block.js' ) // version by file last modified date
	);
	
	remove_filter( 'gutenberg_can_edit_post_type', 'vc_gutenberg_check_disabled' );
	add_filter( 'gutenberg_can_edit_post_type', 'treethemes_gutenberg_check_disabled', 10, 3 ); // increased priority for second pass

	//vc_include_template( 'editors/partials/access-manager-js.tpl.php' );
	require_once( ABSPATH . PLUGINDIR . "/js_composer/js_composer.php" );
	
	global $post, $post_type;

	$treethemes_force_vc_backend = new Vc_Backend_Editor();
	$treethemes_force_vc_backend->registerScripts();
	$treethemes_force_vc_backend->addHooksSettings();
	$treethemes_force_vc_backend->render( $post_type );
}


add_action( 'enqueue_block_assets', 'treethemes_editor_frontend_scripts' );
function treethemes_editor_frontend_scripts() {
	wp_enqueue_style(
		'treethemes-block-frontend', // Handle.
		plugins_url( 'treethemes-block-frontend.css', __FILE__ ), 
		array( 'wp-blocks' ), 
		filemtime( plugin_dir_path( __FILE__ ) . 'treethemes-block-frontend.css' ) // filemtime — Gets file modification time.
	);
	
	/* pode acontecer o ULtimate addons nao estar activo. pensar nesse caso. */
} 

// overrides WPBakery check for gutenberg
if (!function_exists('treethemes_gutenberg_check_disabled')){
	function treethemes_gutenberg_check_disabled(){
		return false; // false forces the vc backend to load even with gutenberg on
	}
}