<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;
use Magento\Search\Helper\Data;
use Magento\Search\ViewModel\AdditionalSearchFormData;
use Magento\Search\ViewModel\ConfigProvider;

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
?>
<?php
/** @var $block Template */
/** @var $helper Data */
/** @var $escaper Escaper */

/** @var $configProvider ConfigProvider */
$configProvider = $block->getData('configProvider');
/** @var $versionManager AdditionalSearchFormData */
$additionalSearchFormData = $block->getData('additionalSearchFormData');
// ox compatiblity with prev magento versions
if($configProvider && method_exists($configProvider, 'getSearchHelperData')){
	$helper = $configProvider->getSearchHelperData();
} else{
	$helper = $this->helper(\Magento\Search\Helper\Data::class);
}


$athlete_search_type = $this->helper('Olegnax\Athlete2\Helper\Helper')->getConfig('athlete2_settings/header/search_type');
$icon	 = '<svg version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" class="a2-icon-search"><use xlink:href="#a2-search-icon"></use></svg>';
$search_icon = '<span class="search-icon-wrapper">' . $icon . '</span>';
$placeholderText = $escaper->escapeHtml(__('Search'));
$input_classes = 'js-input-focus';
if ($athlete_search_type == 'overlay') {
    $input_classes .= ' width-dynamic';
}
?>
<div class="header__search-wrapper ox-move-item ox-move-item-search.slideout ox-move-search ox-move-sticky-search.slideout">
	<div class="ox-overlay-close-btn" aria-label="Close Modal"><span></span></div>
    <?php if ($athlete_search_type == 'overlay') { ?>
		<div class="logo__container">
            <?php echo $block->getLayout()->getBlock('logo')->toHtml(); ?>
		</div>
    <?php } ?>
	<form class="form minisearch" id="search_mini_form" action="<?= $escaper->escapeUrl($helper->getResultUrl()) ?>" method="get">
		<?php // ox check compatiblity with prev magento versions ?>
		<?php if ($configProvider && $additionalSearchFormData && !empty($queryParams = $additionalSearchFormData->getFormData())): ?>
            <?php foreach ($queryParams as $param): ?>
                <input type="hidden" name="<?= $escaper->escapeHtmlAttr($param['name']) ?>"
                       value="<?= $escaper->escapeHtmlAttr($param['value']) ?>"/>
            <?php endforeach; ?>
        <?php endif; ?>
		<div class="field search">
			<div class="control">
				<div class="flashing-cursor"></div>
				<input id="search"
					   data-mage-init='{"quickSearch":{
					   "formSelector":"#search_mini_form",
					   "url":"<?= $escaper->escapeUrl($helper->getSuggestUrl()) ?>",
					   "destinationSelector":"#search_autocomplete"}
					   }'
					   type="text"
					   name="<?= $escaper->escapeHtmlAttr($helper->getQueryParamName()) ?>"
					   value="<?= /* @noEscape */ $helper->getEscapedQueryText() ?>"
					   placeholder="<?= $escaper->escapeHtmlAttr($placeholderText) ?>"
					   class="input-text <?= $escaper->escapeHtmlAttr($input_classes) ?>"
					   maxlength="<?= $escaper->escapeHtmlAttr($helper->getMaxQueryLength()) ?>"
					   role="combobox"
					   aria-haspopup="false"
					   aria-autocomplete="both"
					   autocomplete="off"
					   aria-expanded="false"/>
				<div id="search_autocomplete" class="search-autocomplete"></div>
				<div class="label animated-text--masked">
					<div class="wrap">
						<label class="inner" for="search" data-role="minisearch-label"><?= $escaper->escapeHtml($placeholderText) ?></label>
					</div>
				</div>
                <?= $block->getChildHtml() ?>
			</div>
		</div>
		<div class="actions">
			<button type="submit"
					title="<?= $escaper->escapeHtml(__('Go')) ?>"
					class="action search"
					aria-label="Search"
			>
                <?= $search_icon ?>
				<span><?= $escaper->escapeHtml(__('Go')) ?></span>
			</button>
		</div>
	</form>
</div>

