<?php

/**
 * Gutenberg
 * @category Functions
 * @author Krik
 */

// ACF Gutenberg blocks
// @see advancedcustomfields.com/resources/acf_register_block_type
add_action('acf/init', 'krik_register_acf_block_types');

function krik_register_acf_block_types()
{
	acf_register_block_type(array(
		'name' => 'hero-banner',
		'title' => __('Hero banner'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'cover-image',
		'render_callback' => function () { blade('gutenberg.hero-banner'); }
	));

	acf_register_block_type(array(
		'name' => 'logo-showcase',
		'title' => __('Logo showcase'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'ellipsis',
		'render_callback' => function () { blade('gutenberg.logo-showcase'); }
	));

	acf_register_block_type(array(
		'name' => 'featured-links',
		'title' => __('Featured links'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'admin-links',
		'render_callback' => function () { blade('gutenberg.featured-links'); }
	));

	acf_register_block_type(array(
		'name' => 'featured-videos',
		'title' => __('Featured videos'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'media-video',
		'render_callback' => function () { blade('gutenberg.featured-videos'); }
	));

	acf_register_block_type(array(
		'name' => 'image-text',
		'title' => __('Image & text'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'align-pull-left',
		'render_callback' => function () { blade('gutenberg.image-text'); }
	));

	acf_register_block_type(array(
		'name' => 'banner',
		'title' => __('Banner'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'flag',
		'render_callback' => function () { blade('gutenberg.banner'); }
	));

	acf_register_block_type(array(
		'name' => 'board-members',
		'title' => __('Board members'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'flag',
		'render_callback' => function () { blade('gutenberg.board-members'); }
	));

	acf_register_block_type(array(
		'name' => 'featured-news',
		'title' => __('Featured news'),
		'category' => 'krik-blocks',
		'mode' => 'edit',
		'icon' => 'flag',
		'render_callback' => function () { blade('gutenberg.featured-news'); }
	));

	acf_register_block_type(array(
		'name' => 'form',
		'title' => __('Form'),
		'category' => 'krik-blocks',
		'icon' => 'pressthis',
		'mode' => 'edit',
		'render_callback' => function () { blade('gutenberg.form'); }
	));
}

// Allow Gutenberg blocks
add_filter('allowed_block_types_all', 'krik_gutenberg_block_types', 10, 2);

// Register new gutenberg category
add_filter( 'block_categories_all', 'krik_block_category', 10, 2);

function krik_gutenberg_block_types($allowed_blocks, $post) {
	$allowed_blocks = array(
		// ACF
		'acf/hero-banner',
		'acf/logo-showcase',
		'acf/featured-links',
		'acf/featured-videos',
		'acf/image-text',
		'acf/banner',
		'acf/board-members',
		'acf/featured-news',
		'acf/form',

		// Common blocks
		'core/paragraph',
		'core/image',
		'core/heading',
		// 'core/gallery',
		'core/list',
		'core/list-item',
		// 'core/quote',
		// 'core/audio',
		// 'core/cover',
		// 'core/file',
		// 'core/video',

		// Formatting
		'core/table',
		// 'core/verse',
		// 'core/code',
		// 'core/freeform',
		'core/html',
		// 'core/preformatted',
		// 'core/pullquote',

		// Layout Elements
		// 'core/button',
		// 'core/columns',
		// 'core/media-text',
		// 'core/more',
		// 'core/nextpage',
		// 'core/separator',
		'core/spacer',

		// Widgets
		'core/shortcode',
		// 'core/archives',
		// 'core/categories',
		// 'core/latest-comments',
		// 'core/latest-posts',

		// Embeds
		// 'core/embed',
		// 'core-embed/twitter',
		// 'core-embed/youtube',
		// 'core-embed/facebook',
		// 'core-embed/instagram',
		// 'core-embed/wordpress',
		// 'core-embed/soundcloud',
		// 'core-embed/spotify',
		// 'core-embed/flickr',
		// 'core-embed/vimeo',
		// 'core-embed/animoto',
		// 'core-embed/cloudup',
		// 'core-embed/collegehumor',
		// 'core-embed/dailymotion',
		// 'core-embed/funnyordie',
		// 'core-embed/hulu',
		// 'core-embed/imgur',
		// 'core-embed/issuu',
		// 'core-embed/kickstarter',
		// 'core-embed/meetup-com',
		// 'core-embed/mixcloud',
		// 'core-embed/photobucket',
		// 'core-embed/polldaddy',
		// 'core-embed/reddit',
		// 'core-embed/reverbnation',
		// 'core-embed/screencast',
		// 'core-embed/scribd',
		// 'core-embed/slideshare',
		// 'core-embed/smugmug',
		// 'core-embed/speaker',
		// 'core-embed/ted',
		// 'core-embed/tumblr',
		// 'core-embed/videopress',
		// 'core-embed/wordpress-tv',
	);

	return $allowed_blocks;
}

function krik_block_category( $categories, $post ) {
	return array_merge(
		$categories,
		array(
			array(
				'slug' => 'krik-blocks',
				'title' => 'Krik',
			),
		)
	);
}
