<?php
/*====================================================
/* EDITOR BLOCK STYLE
/*====================================================*/
function rt_block_editor_style() {
	add_theme_support('editor-styles');
	add_editor_style('assets/css/utilities.min.css');
	add_editor_style('assets/css/style.min.css');
	add_editor_style('assets/css/editor-style.min.css');
}
add_action('after_setup_theme', 'rt_block_editor_style');


/*====================================================
/* ADD CLASS NAME ADMIN BODY
/*====================================================*/
function rt_block_admin_classes($classes) {

	$classes = 'retheme-root retheme-default-scheme';

	return $classes;
}
add_filter('admin_body_class', 'rt_block_admin_classes');

/*====================================================
/* CUSTOM COLOR PALETTE FROM CUSTOMIZER
/*====================================================*/
function rt_block_customizer($theme_json) {

	$new_data = [
		'version'  => 3,
		'settings' => [
			'color' => [
				'palette'    => [
					[
						'slug'  => 'primary',
						'color' => rt_get_option('global_color_primary', rt_get_theme('color')['primary']),
						'name'  => 'Primary',
					],
					[
						'slug'  => 'heading',
						'color' => rt_get_option('global_color_heading', rt_get_theme('color')['heading']),
						'name'  => 'Heading',
					],
					[
						'slug'  => 'body',
						'color' => rt_get_option('global_color_body', rt_get_theme('color')['body']),
						'name'  => 'body',
					],
					[
						'slug'  => 'meta',
						'color' => rt_get_option('global_color_meta', rt_get_theme('color')['meta']),
						'name'  => 'Meta',
					],
					[
						'slug'  => 'text-link',
						'color' => rt_get_option('global_color_link', rt_get_theme('color')['text-link']),
						'name'  => 'Link',
					],
					[
						'slug'  => 'text-link-active',
						'color' => rt_get_option('global_color_link_active', rt_get_theme('color')['text-link-active']),
						'name'  => 'Link Active',
					],
					[
						'slug'  => 'background',
						'color' => rt_get_option('global_color_background', rt_get_theme('color')['background']),
						'name'  => 'Background',
					],
					[
						'slug'  => 'foreground',
						'color' => rt_get_option('global_color_foreground', rt_get_theme('color')['foreground']),
						'name'  => 'Foreground',
					],
					[
						'slug'  => 'outline',
						'color' => rt_get_option('global_color_border', rt_get_theme('color')['outline']),
						'name'  => 'Outline',
					],
					[
						'slug'  => 'highlight',
						'color' => '#fd704f',
						'name'  => 'Highlight',
					]
				],
			],
			'typography' => [
				'fontFamilies' => [
					[
						'slug' => 'heading',
						'fontFamily' => rt_get_option('typography_heading', rt_get_theme('typography')['heading'])['font-family'],
						'name' => 'Heading'
					],
					[
						'slug' => 'body',
						'fontFamily' => rt_get_option('typography_body', rt_get_theme('typography')['body'])['font-family'],
						'name' => 'Body'
					],
				],
			],
		],
	];


	return $theme_json->update_with($new_data);
}
add_filter('wp_theme_json_data_theme', 'rt_block_customizer');

/*====================================================
/* DISABLE BLOCK EDITOR FOR POST TYPE
/*====================================================*/
function rt_block_disable_block_editor($current_status, $post_type) {
	if ($post_type === 'post' && rt_get_option('disable_block_editor_post', false)) {
		return false;
	}

	return $current_status;
}
add_filter('use_block_editor_for_post_type', 'rt_block_disable_block_editor', 10, 2);


/*====================================================
/* BLOCK SUPPORT TEMPLATE PART
/*====================================================*/
function rt_block_template_part_support() {
	if (rt_get_option('block_template_part_support', false)) {
		add_theme_support('block-template-parts');
	}
}
add_action('after_setup_theme', 'rt_block_template_part_support');
