<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

function haup_shortcode_insert_js_init(){
	//スクリプトを登録
	wp_register_script(
		'haup-shortcode-insert',
		plugin_dir_url( __FILE__ ) .'shortcode-insert.js',
		array( 'lodash', 'wp-rich-text','wp-element','wp-components', 'wp-blocks', 'wp-editor', 'wp-keycodes'),
		haup_plugin_version(),
		array( 
			'strategy'  => 'defer',
			'in_footer' => true, // Note: This is the default value.
		)
	);

	//スクリプトをエンキュー
	wp_enqueue_script('haup-shortcode-insert');

	//スクリプトに渡すための文字列と翻訳可能文字列を紐づけて配列にする
	$localize_val = array(
		'buttontitle' => __('Insert HAUP shortcode','hima-art-utility'),
		'listtitle' => __('Shortcode List','hima-art-utility'),
		'Info' => __('Other shortcodes can be inserted by selecting them from the Add Block → Pattern tab.','hima-art-utility'),
		'moddate' => __('Last updated date','hima-art-utility'),
		'tooltip' => __('Tooltips','hima-art-utility'),
		'cfvalue' => __('Custom field values','hima-art-utility'),
		'reuse' => __('Reusable block (ID specified insertion)','hima-art-utility'),
		'excerpt' => __('Description or excerpt','hima-art-utility'),
		'oldpost' => __('Let me know this is an old post','hima-art-utility'),
		'pwareki' => __('Display the publication date in Japanese calendar format','hima-art-utility'),
		'mwareki' => __('Display the last update date including the Japanese calendar date','hima-art-utility'),
		'age' => __('Age (months elapsed) display','hima-art-utility'),
		'screenshot' => __('URL Screen Shot','hima-art-utility'),
		'qrcode' => __('Display the page URL as a QR code','hima-art-utility'),
		'mailad' => __('Email address obfuscation','hima-art-utility'),
		'maillink' => __('Email Link Obfuscation','hima-art-utility')
		);

	//wp_localize_scriptを使ってスクリプトへ配列を渡す
	wp_localize_script('haup-shortcode-insert', 'ShortcodeTitleVal', $localize_val);

}
add_action('enqueue_block_editor_assets','haup_shortcode_insert_js_init');

function haup_dashicon_sc_in_blocktoolbar(){
	if(isset( GetOP09_addcontent()['use-custom-design-with-dashicon'] ) && GetOP09_addcontent()['use-custom-design-with-dashicon'] == 1 ){
		$dicon_shortcode[] = [ // $all_shortcodes の末尾に追加（配列の要素追加）
			'name' => 'dicon',
			'title' => __( 'Dashicon', 'hima-art-utility' ), // 追加したいアイテムの名称
			'icon' => 'beer', 
			'shortcode' => '[dicon icon="" size="" color="" marginl="" marginr="" align=""]'
		];
	}else{
		$dicon_shortcode = '';
	}

	$localize_val = array(
		'dicon'            => $dicon_shortcode, // ここには条件判定後の最終的なリストが入っている
	);

	wp_localize_script('haup-shortcode-insert', 'DashIconInBlockToolBar', $localize_val);
}
add_action('enqueue_block_editor_assets','haup_dashicon_sc_in_blocktoolbar' );

function haup_admin_short_insert_style_init(){
		wp_enqueue_style(
			'haup-shortcode-insert-style',
			plugin_dir_url( __FILE__ ) .'shortcode-insert.css',
			'array()',
			haup_plugin_version(),
		);
}
add_action('enqueue_block_editor_assets','haup_admin_short_insert_style_init');