<?php
/**
 * This file is used to markup the filter type buttons.
 *
 * @since      1.0
 *
 * @package    SiteEase_Smart_Product_Filtering_Engine
 * @subpackage SiteEase_Smart_Product_Filtering_Engine/public/partials/filter-types
 */

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$field_keys = wp_list_pluck($fields, 'type');
$is_enabled_buttons = ifqpf_get_option('filter_buttons_display');
$is_enabled_filter_button = ifqpf_get_option('filter_button_display');
$is_enabled_reset_button = ifqpf_get_option('reset_filter_button_display');

if( $is_enabled_buttons && $is_enabled_filter_button ){
	$filter_button_text = esc_html( trim( ifqpf_get_option('filter_button_text') ) );
	$submit_name = ( $filter_button_text ) ? esc_html( $filter_button_text ) : esc_html__( 'Filter', 'siteease-smart-product-filtering-engine' );
}

if( $is_enabled_buttons && $is_enabled_reset_button ){
	$reset_filter_button_text = esc_html( trim( ifqpf_get_option('reset_filter_button_text') ) );
	$reset_filter_button_text = ( $reset_filter_button_text ) ? esc_html( $reset_filter_button_text ): esc_html__( 'Reset', 'siteease-smart-product-filtering-engine' );

}

$not_allowed = array('sorting', 'search');

?>

<?php
$match = array_intersect($not_allowed, $field_keys);
?>
<?php if( $is_enabled_buttons === 'yes' ) { ?>
	<div class="ifqpf-submit">
	<?php if ( $is_enabled_filter_button === 'yes' && ( ( ( count( $fields ) === 1 && empty( $match ) ) || ( count( $match ) < count( $fields ) ) ) || count( $fields ) > count( $not_allowed ) ) ) { ?>
			<button type="submit" name="ifqpf_submit" class="ifqpf-btn ifqpf-submit" id="ifqpf_submit"><?php echo esc_attr($submit_name); ?></button>
	<?php } ?>
	<?php if( $is_enabled_reset_button === 'yes' ) { ?>
		<button type="button" class="ifqpf-btn ifqpf-reset" id="ifqpf_reset"><?php echo esc_attr($reset_filter_button_text); ?></button>
	<?php } ?>
	</div>
<?php } ?>