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

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

$display_filter_heading = ifqpf_get_option('display_filter_heading');

if( $display_filter_heading === 'yes' ){
	$filter_heading = trim( ifqpf_get_option('filter_heading') );
}
?>
<?php if (isset($fields) && !empty( $fields ) ) { ?>
	<div class="ifqpf-wrap">
		<div class="ifqpf-mobile-overlay"></div>
		<div class="ifqpf-mobile-wrap">
			<button class="ifqpf-mobile-btn" type="button"><?php echo !empty( $filter_heading ) ? esc_html($filter_heading) : esc_html__('Filter','siteease-smart-product-filtering-engine'); ?></button>
		</div>
		<div class="ifqpf-form-wrap">
			<div class="ifqpf-form-header">
				<?php if( $display_filter_heading === 'yes' ) { ?>
					<h2 class="ifqpf-form-heading"><?php echo !empty( $filter_heading ) ? esc_html($filter_heading) : esc_html__('Filter', 'siteease-smart-product-filtering-engine'); ?></h2>
				<?php } ?>
				<a href="#" class="ifqpf-mobile-close"><?php echo esc_html__('x','siteease-smart-product-filtering-engine');?></a>
			</div>
			<form class="ifqpf-from" method="post">
				<?php foreach ($fields as $f_key => $field) { ?>
					<?php
					$filter_type = $field['type'];
					$file_name = sprintf("ifqpf-type-%s.php", $filter_type);

					if( isset( $field['value'] ) && !empty( $field['value'] ) ){
						$value = $field['value'];
						$types_agrgs = array($filter_type=>$value);
					}else{
						$types_agrgs = array();
					}
					
					if( $filter_type === 'buttons' ) {
						$types_agrgs['fields'] = $fields;
					}

					?>
					
					<?php ifqpf_get_template('filter-types/'.$file_name, $types_agrgs); ?>
					
				<?php } ?>
			</form>
		</div>
	</div>
	<p class="quick-result-count-display"></p>
<?php } ?>