<?php
declare( strict_types=1 );

use FiboFilters\Config\Env;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/*
 * ╭────────╮
 * | Colors |
 * ╰────────╯
 */
add_action(
	'wp_enqueue_scripts',
	function () {
		wp_add_inline_style(
			'fibofilters',
			'body {
 --fibofilters--colors--base: var( --theme-palette-color-1, var( --fibofilters--colors--base-org ) );
 --fibofilters--colors--link: var( --theme-link-initial-color, var( --fibofilters--colors--link-org ) );
 }'
		);
	}
);

/*
 * ╭─────────────────────╮
 * | Pagination selector |
 * ╰─────────────────────╯
 */
add_filter( 'fibofilters/config/pagination_selectors', fn() => [ '.ct-pagination' ] );

/*
 * ╭─────────────────╮
 * | Pagination args |
 * ╰─────────────────╯
 */
add_filter(
	'fibofilters/config/pagination_args',
	function ( $args ) {
		return wp_parse_args(
			[
				'type'          => 'plain',
				// This class doesn't matter. What matters is that there is a wrapper.
				'wrapper_class' => 'fibofilters-inner-pagination',
			],
			$args
		);
	}
);

add_action(
	'wp_enqueue_scripts',
	function () {
		ob_start();
		?>
		<script>
			if (typeof fiboFilters !== 'undefined') {
				function fibofiltersBlocksyFix() {
					if (typeof ctEvents !== 'undefined' && typeof ctEvents.trigger === 'function') {
						ctEvents.trigger('blocksy:frontend:init');
					}
				}

				fiboFilters.hooks.addAction('fiboFilters.renderer.products_loaded', 'fibofilters', fibofiltersBlocksyFix);
				fiboFilters.hooks.addAction('fiboFilters.renderer.product_placeholders_overwritten', 'fibofilters', fibofiltersBlocksyFix);
			}
		</script>
		<?php
		$this->enqueue_inline_script( (string) ob_get_clean() );
	}
);

