<?php
declare( strict_types=1 );

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

add_filter(
	'fibofilters/config/offcanvas_position',
	function (): string {
		$sidebar_position = get_theme_mod( 'storefront_layout', 'right' );
		if ( in_array( $sidebar_position, [ 'left', 'right' ], true ) ) {
			return $sidebar_position;
		}

		return 'right';
	}
);

add_filter(
	'fibofilters/config/pagination_args',
	function ( $args ) {
		return wp_parse_args(
			[
				'end_size' => 1,
				'mid_size' => 1,
			],
			$args
		);
	}
);

/**
 * ╭─────────────────────────╮
 * | Pagination placeholders |
 * ╰─────────────────────────╯
 */
add_action(
	'template_redirect',
	function () {
		$context = apply_filters( 'fibofilters/request/get_context', [] );

		if (
			! empty( $context['show_filters'] ) &&
			! empty( $context['conditions']['has_active_filters'] ) &&
			wc_get_loop_prop( 'total_pages' ) === 1
		) {
			add_filter( 'fibofilters/front/force_display_pagination_placeholder', '__return_false' );

			// Storefront hooks pagination on non-standard priorities.
			add_action(
				'woocommerce_before_shop_loop',
				function () {
					do_action( 'fibofilters/front/display_pagination_placeholder' );
				},
				30
			);
			add_action(
				'woocommerce_after_shop_loop',
				function () {
					do_action( 'fibofilters/front/display_pagination_placeholder' );
				},
				30
			);
		}
	}
);
