<?php
declare( strict_types=1 );

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

/**
 * ╭────────────────────────╮
 * | Products loop selector |
 * ╰────────────────────────╯
 */
add_filter(
	'fibofilters/config/products_loop_selectors',
	function ( $selectors ) {

		$selectors   = [];
		$selectors[] = '.isotope-container';

		return $selectors;
	}
);

/*
 * ╭─────────────────────────────────────╮
 * | Load more button | Infinite scroll  |
 * ╰─────────────────────────────────────╯
 */
add_action(
	'wp_footer',
	function () {
		?>
		<script>
			const buttonContainer = document.querySelector('.fibofilters-show-more-button-container');
			const infiniteScrollContainer = document.querySelector('.fibofilters-infinite-scroll-trigger-container');
			const postContent = document.querySelector('.post-content');

			if (postContent) {
				if (buttonContainer) {
					postContent.appendChild(buttonContainer);
				}
				if (infiniteScrollContainer) {
					postContent.appendChild(infiniteScrollContainer);
				}
			}
		</script>
		<?php
	}
);
