<?php
/**
 * Microwidget search view.
 *
 * @package The7\Templates
 */

defined( 'ABSPATH' ) || exit;

$show_icon = presscore_config()->get( 'header.elements.search.icon.enabled' );

$class = 'disabled' === $show_icon ? ' mini-icon-off' : '';

$caption = presscore_config()->get( 'header.elements.search.caption' );
if ( $caption ) {
	$caption = '<span>' . esc_html( $caption ) . '</span>';
}

$input_caption = presscore_config()->get( 'header.elements.search.input.caption' );

if ( ! $caption && 'disabled' !== $show_icon ) {
	$class .= ' text-disable';
}

$class_icon = '';
if ( presscore_config()->get( 'header.elements.search.icon' ) === 'disabled' ) {
	$class_icon = ' search-icon-disabled';
}

if ( ! $input_caption ) {
	$input_caption = '&nbsp;';
}

$custom_icon = '';
if ( presscore_config()->get( 'header.elements.search.icon' ) === 'custom' ) {
	$custom_icon = '<i class="' . esc_attr( presscore_config()->get( 'header.elements.search.custom.icon' ) ) . '"></i>';
}

$custom_search_icon = '';
if ( 'custom' === $show_icon ) {
	$custom_search_icon = '<i class=" mw-icon ' . esc_attr( presscore_config()->get( 'header.elements.search.icon.custom' ) ) . '"></i>';
}
?>
<form class="searchform mini-widget-searchform<?php echo $class_icon; ?>" role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">

	<div class="screen-reader-text"><?php esc_html_e( 'Search:', 'the7mk2' ); ?></div>

	<?php if ( in_array( presscore_config()->get( 'header.elements.search.style' ), array( 'classic', 'animate_width' ) ) ) : ?>

		<input type="text" aria-label="<?php esc_attr_e( 'Search', 'the7mk2' ); ?>" class="field searchform-s" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" placeholder="<?php echo esc_html( $input_caption ); ?>" title="<?php esc_attr_e( 'Search form', 'the7mk2' ) ?>"/>
		<a href="" class="search-icon"><?php echo $custom_icon; ?></a>

	<?php elseif ( presscore_config()->get( 'header.elements.search.style' ) === 'popup' ) : ?>

		<a href="" class="submit<?php echo $class; ?>"><?php echo $custom_search_icon . $caption; ?></a>
		<div class="popup-search-wrap">
			<input type="text" aria-label="<?php esc_attr_e( 'Search', 'the7mk2' ); ?>" class="field searchform-s" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" placeholder="<?php echo esc_html( $input_caption ); ?>" title="<?php esc_attr_e( 'Search form', 'the7mk2' ) ?>"/>
			<a href="" class="search-icon"><?php echo $custom_icon; ?></a>
		</div>

	<?php else : ?>

		<div class='overlay-search-wrap'>
			<input type="text" autofocus aria-label="<?php esc_attr_e( 'Search', 'the7mk2' ); ?>" class="field searchform-s" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" placeholder="<?php echo esc_html( $input_caption ); ?>" title="<?php esc_attr_e( 'Search form', 'the7mk2' ) ?>"/>
			<a href="" class="search-icon"><?php echo $custom_icon; ?></a>
		</div>


		<a href="" class="submit<?php echo $class; ?>"><?php echo $custom_search_icon . $caption; ?></a>

		<?php
	endif;

	do_action( 'presscore_header_searchform_fields' );
	?>
	<?php if ( of_get_option( 'header-elements-search-by' ) === 'products' ) : ?>
		<input type="hidden" name="post_type" value="product">
	<?php endif; ?>
	<input type="submit" class="assistive-text searchsubmit" value="<?php esc_attr_e( 'Go!', 'the7mk2' ); ?>"/>
</form>
