<?php

/**
EDITOR
 */
add_action('enqueue_block_editor_assets', 'dragblock_settings_panel_editor_assets');
function dragblock_settings_panel_editor_assets()
{
	$panel = 'settings';
	dragblock_enqueue("dragblock-{$panel}-panel", "build/applications/editor-panel-{$panel}/client/index.js", array(DRAGBLOCK_EDITOR_INIT_SLUG));
	dragblock_enqueue("dragblock-{$panel}-panel", "build/applications/editor-panel-{$panel}/client/index.css");
}


/**
FRONTEND
 */
add_action('wp_enqueue_scripts', 'dragblock_settings_frontend_enqueue', 1);
function dragblock_settings_frontend_enqueue()
{
	global $dragblock_js;
	if (!$dragblock_js) {
		return;
	}
	$dragblock_js_str = implode('', $dragblock_js);
	// slider
	if (strpos($dragblock_js_str, 'new Swiper') !== false) {
		wp_enqueue_style(
			'dragblock-swiper-css',
			DRAGBLOCK_URL . '/assets/plugins/swiper/swiper.min.css',
			array(),
			'11.1.15'
		);		
		wp_enqueue_script(
			'dragblock-swiper-js',
			DRAGBLOCK_URL . '/assets/plugins/swiper/swiper.min.js',
			array(),
			'11.1.15',
			true
		);
	}

	// visual-compare
	if (strpos($dragblock_js_str, 'new VisualCompare') !== false) {
		//wp_die('loading visual-compare: '. $dragblock_js_str);
		wp_enqueue_style(
			'dragblock-visual-compare-css',
			DRAGBLOCK_URL . '/assets/plugins/visualcompare/visualcompare.min.css',
			array(),
			'0.1.0'
		);		
		wp_enqueue_script(
			'dragblock-visual-compare-js',
			DRAGBLOCK_URL . '/assets/plugins/visualcompare/visualcompare.min.js',
			array(),
			'0.1.0',
			true
		);
	}
}
