<?php
/**
 * BLOCK: Vehicle Archive
 *
 * Gutenberg Vehicle Archive Block assets.
 *
 * @since   1.0
 * @package Mobile_API
 */

defined( 'ABSPATH' ) || exit;

/**
 * Enqueue the block's assets for the editor.
 *
 * `wp-blocks`: Includes block type registration and related functions.
 * `wp-element`: Includes the WordPress Element abstraction for describing the structure of your blocks.
 * `wp-i18n`: To internationalize the block's text.
 *
 * @since 1.0.0
 */
function mobile_api_vehicle_archive_block() {
	wp_register_script( 'mobile_api-vehicle-archive-block-script', plugins_url( 'block.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'wp-server-side-render', 'wp-block-editor', 'wp-components', 'wp-i18n' ), filemtime( plugin_dir_path( __FILE__ ) . 'block.js' ), true );
	wp_register_style( 'mobile_api-vehicle-archive-block-style', plugins_url( 'style.css', __FILE__ ), array(), filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ) );

	register_block_type( 'mobile-api/vehicle-archive', array(
		'api_version'     => 3,
		'supports'        => array( 'align' => true, 'alignWide' => true ),
		'editor_script'   => 'mobile_api-vehicle-archive-block-script',
		'style'           => 'mobile_api-vehicle-archive-block-style',
		'render_callback' => 'mobile_api_shortcode_vehicle_archive',
		'attributes'      => array(
			'category'    => array(
				'type'    => 'array',
				'default' => array()
			)
		)
	) );
}
add_action( 'init', 'mobile_api_vehicle_archive_block' );


/* if ( function_exists( 'register_block_type' ) )
	new Mobile_API_Vehicle_Archive_Block();

class Mobile_API_Vehicle_Archive_Block {
	public function __construct() {
		add_action( 'init', [ $this, 'gutenberg_block_register_block' ] );
		add_action( 'enqueue_block_editor_assets', [ $this, 'gutenberg_block_editor_scripts' ] );
	}

	public function gutenberg_block_register_block() {
		register_block_type( 'mobile-api/vehicle-archive', [
			'editor_script'   => 'mobile_api-vehicle-archive-block-script',
			'editor_style'    => 'mobile_api-vehicle-archive-block-editor-style',
			'style'           => 'mobile_api-vehicle-archive-block-style',
			'render_callback' => [ $this, 'mobile_api_shortcode_vehicle_archive' ],
			'attributes'      => [
				'category'    => [
					'type'    => 'array'
				],
				'design'      => [
					'type'    => 'string',
					'default' => 'default'
				]
			]
		] );
	}

	public function gutenberg_block_editor_scripts() {
		wp_enqueue_script( 'mobile_api-vehicle-archive-block-script', plugins_url( 'block.js', __FILE__ ), array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ), filemtime( plugin_dir_path( __FILE__ ) . 'block.js' ), true );
		wp_register_style( 'mobile_api-vehicle-archive-block-editor-style', plugins_url( 'editor.css', __FILE__ ), array( 'wp-edit-blocks' ), filemtime( plugin_dir_path( __FILE__ ) . 'editor.css' ) );
		wp_register_style( 'mobile_api-vehicle-archive-block-style', plugins_url( 'style.css', __FILE__ ), array(), filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ) );
	}
} */
