<?php
/**
 * Plugin Name:       {{title}}
{{#pluginURI}}
 * Plugin URI:        {{{pluginURI}}}
{{/pluginURI}}
{{#description}}
 * Description:       {{description}}
{{/description}}
 * Requires at least: 6.1
 * Requires PHP:      7.0
 * Version:           {{version}}
{{#author}}
 * Author:            {{author}}
{{/author}}
{{#license}}
 * License:           {{license}}
{{/license}}
{{#licenseURI}}
 * License URI:       {{{licenseURI}}}
{{/licenseURI}}
 * Text Domain:       {{textdomain}}
{{#domainPath}}
 * Domain Path:       {{{domainPath}}}
{{/domainPath}}
{{#updateURI}}
 * Update URI:        {{{updateURI}}}
{{/updateURI}}
 *
 * @package           {{namespace}}
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Registers all block assets so that they can be enqueued through the block editor
 * in the corresponding context.
 *
 * @see https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/applying-styles-with-stylesheets/
 */
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
	$dir = __DIR__;

	$index_js = 'index.js';
	wp_register_script(
		'{{namespace}}-{{slug}}-block-editor',
		plugins_url( $index_js, __FILE__ ),
		array(
			'wp-block-editor',
			'wp-blocks',
			'wp-i18n',
			'wp-element',
		),
		filemtime( "$dir/$index_js" )
	);
	wp_set_script_translations( '{{namespace}}-{{slug}}-block-editor', '{{textdomain}}' );

	$editor_css = 'editor.css';
	wp_register_style(
		'{{namespace}}-{{slug}}-block-editor',
		plugins_url( $editor_css, __FILE__ ),
		array(),
		filemtime( "$dir/$editor_css" )
	);

	$style_css = 'style.css';
	wp_register_style(
		'{{namespace}}-{{slug}}-block',
		plugins_url( $style_css, __FILE__ ),
		array(),
		filemtime( "$dir/$style_css" )
	);

	register_block_type(
		$dir,
		array(
			'editor_script' => '{{namespace}}-{{slug}}-block-editor',
			'editor_style'  => '{{namespace}}-{{slug}}-block-editor',
			'style'         => '{{namespace}}-{{slug}}-block',
		)
	);
}
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
