<?php

/**
 * Filter content
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $wpcb_field;

$wpcb_filter = $wpcb_field;

$class = '';
if ( isset( $wpcb_field['collapsible'] ) && $wpcb_field['collapsible'] ) {
	$class .= ' wpcb-collapsible';
	
	if ( isset( $wpcb_field['field']['collapsed'] ) && 'no' !== $wpcb_field['field']['collapsed'] ) {
		$class .= ' wpcb-collapsed';
	}
}

$filter_id = wpcb_sanitize_title($wpcb_filter['label']);
?>

<div class="wpcb-configurator-field wpcb-configurator-field-filter<?php echo esc_attr( $class ); ?>"<?php echo ' data-label="' . esc_attr( $wpcb_filter['label'] ) . '"'; ?>>

	<div class="wpcb-configurator-field-filter-header">
	
		<div class="wpcb-configurator-field-filter-title">
			<strong class="wpcb-configurator-filter-group-label">
				<?php echo esc_attr( $wpcb_filter['label'] ); ?>
			</strong>
			<p class="wpcb-configurator-field-filter-value"></p>
		</div>

		<?php if ( isset( $wpcb_filter['description'] ) && '' !== $wpcb_filter['description'] ) : ?>
			<button class="wpcb-view-field-filter-details" data-id="wpcb-configurator-field-filter-<?php echo esc_attr( $filter_id ); ?>-description">
				<?php echo wp_kses( wpcb_get_icon( 'info' ), wpcb_get_icon_kses_args() ); ?>
			</button>
		<?php endif; ?>

	</div>

	<!-- <div class="wpcb-configurator-field-filter-tags">
	</div>
	<div class="wpcb-configurator-field-filter-search">
		<form action="">
			<label for="search" class="wpcb-configurator-input">
				<input type="text" name="search" value="">
			</label>
			<button class="wpcb-button" type="submit">Search</button>
		</form>
	</div> -->

	<div class="wpcb-configurator-field-filter-main">
		<?php
		if ( $wpcb_filter['show_inline'] ) :
			// Inline options
			foreach ( $wpcb_filter['subfields'] as $wpcb_field ) {
				$wpcb_field['id'] = $filter_id;
				$wpcb_field['name'] = $filter_id;

				include 'choice.php';
			}

			if ( isset( $wpcb_filter['clear_label'] ) && '' !== $wpcb_filter['clear_label'] ) :
				?>
				<a href="#" class="wpcb-configurator-filter-clear-action hidden">
					<?php echo wp_kses( wpcb_get_icon( 'bin' ), wpcb_get_icon_kses_args() ); ?>
					<span class="wpcb-configurator-form-action-label"><?php echo esc_attr( $wpcb_filter['clear_label'] ); ?></span>
				</a>
				<?php
			endif;
		else:
			// Panel options
			ob_start();
			foreach ( $wpcb_filter['subfields'] as $wpcb_field ) {
				$wpcb_field['id'] = $filter_id;
				$wpcb_field['name'] = $filter_id;

				include 'choice.php';
			}

			if ( isset( $wpcb_filter['clear_label'] ) && '' !== $wpcb_filter['clear_label'] ) :
				?>
				<a href="#" class="wpcb-configurator-filter-clear-action hidden">
					<?php echo wp_kses( wpcb_get_icon( 'bin' ), wpcb_get_icon_kses_args() ); ?>
					<span class="wpcb-configurator-form-action-label"><?php echo esc_attr( $wpcb_filter['clear_label'] ); ?></span>
				</a>
				<?php
			endif;

			$panel_content = ob_get_clean();
			$panel_args = array(
				'description' => $panel_content,
				'id' => 'wpcb-configurator-field-' . $filter_id . '-panel',
			);
			wpcb_display_panel_html_safe( $wpcb_filter['label'], $panel_args ); 
			?>

			<a href="#" class="wpcb-filter-item wpcb-view-field-filter-details" data-id="<?php echo 'wpcb-configurator-field-' . esc_attr( $filter_id ) . '-panel'; ?>" data-label="<?php echo esc_attr( $wpcb_filter['button_text'] ); ?>">
				<div class="wpcb-filter-item-thumbnail"></div>
				<div class="wpcb-filter-item-details">
					<p class="wpcb-filter-item-label"><?php echo esc_attr( $wpcb_filter['button_text'] ); ?></p>
					<small class="wpcb-filter-item-note"></small>
				</div>
				<div class="wpcb-filter-item-totals">
					<p class="wpcb-filter-item-price"></p>
				</div>
				<div class="wpcb-filter-item-icon">
					<?php
					echo wp_kses( wpcb_get_icon('chevron-down'), wpcb_get_icon_kses_args() );
					?>
				</div>
			</a>

		<?php endif; ?>

	</div>

	<?php if ( ( isset( $wpcb_filter['description'] ) && '' !== $wpcb_filter['description'] ) ) : ?>

		<?php 
		$panel_args = array(
			'description' => wpautop( $wpcb_filter['description'] ),
			'id' => 'wpcb-configurator-field-filter-' . esc_attr( $filter_id ) . '-description',
		);
		wpcb_display_panel_html_safe( $wpcb_filter['label'], $panel_args ); 
		?>

	<?php endif; ?>

</div>