<?php
//==============================================================================
// Smart Search Pro v2024-7-11
// 
// Author: Clear Thinking, LLC
// E-mail: johnathan@getclearthinking.com
// Website: http://www.getclearthinking.com
// 
// All code within this file is copyright Clear Thinking, LLC.
// You may not copy or reuse code within this file without written permission.
//==============================================================================
?>

<style type="text/css">
	.smartsearch-pro {
		margin-bottom: 50px;
	}
	.smartsearch-pro a {
		border: 1px solid rgba(0, 0, 0, 0);
		display: inline-block;
		font-size: 15px;
		font-weight: bold;
		padding: 10px 0;
		text-align: center;
		text-decoration: none;
	}
	@media (max-width: 767px) {
		.smartsearch-pro a {
			display: block;
			width: 100% !important;
		}
	}
	.smartsearch-pro a:hover {
		border: 1px solid #CCC;
		box-shadow: 0 0 10px #CCC;
	}
	.smartsearch-pro .category {
		width: <?php echo (100 / $settings['categories_per_row']) - 1; ?>%;
	}
	.smartsearch-pro .information {
		width: <?php echo (100 / $settings['informations_per_row']) - 1; ?>%;
	}
	.smartsearch-pro .manufacturer {
		width: <?php echo (100 / $settings['manufacturers_per_row']) - 1; ?>%;
	}
	.smartsearch-pro img {
		margin-bottom: 10px;
	}
	.smartsearch-pro .category img {
		height: <?php echo (int)$settings['category_image_height']; ?>px;
		width: <?php echo (int)$settings['category_image_width']; ?>px;
	}
	.smartsearch-pro .manufacturer img {
		height: <?php echo (int)$settings['manufacturer_image_height']; ?>px;
		width: <?php echo (int)$settings['manufacturer_image_width']; ?>px;
	}
</style>

<div id="smartsearch-pro">
	<?php foreach ($sorting as $sort_order => $page_type) { ?>
		
		<?php if ($page_type == 'category' && !empty($smartsearch_categories)) { ?>
			<div id="category-results" class="smartsearch-pro" <?php if (isset($sorting['category'])) echo 'style="display: none"'; ?>>
				<h2><?php echo html_entity_decode($settings['category_heading_' . $language_code], ENT_QUOTES, 'UTF-8'); ?></h2>
				<?php $smartsearch_categories = array_slice($smartsearch_categories, 0, $settings['category_limit']); ?>
				<?php foreach ($smartsearch_categories as $category) { ?>
					<?php $link_route = ($settings['category_from_products']) ? 'product/search' : 'product/category'; ?>
					<?php $link_parameter = ($settings['category_from_products']) ? 'category_id' : 'path'; ?>
					<a class="category" href="<?php echo $url_library->link($link_route, $link_parameter . '=' . $category['category_id'] . $search_phrase); ?>">
						<?php if ($settings['category_image_width']) { ?>
							<img src="<?php echo $tool_image->resize(!empty($category['image']) ? $category['image'] : 'placeholder.png', $settings['category_image_width'] * 2, $settings['category_image_height'] * 2); ?>" />
							<br>
						<?php } ?>
						<?php echo $category['name']; ?>
					</a>
				<?php } ?>
			</div>
		<?php } ?>
		
		<?php if ($page_type == 'information' && !empty($smartsearch_informations)) { ?>
			<div id="information-results" class="smartsearch-pro" <?php if (isset($sorting['information'])) echo 'style="display: none"'; ?>>
				<h2><?php echo html_entity_decode($settings['information_heading_' . $language_code], ENT_QUOTES, 'UTF-8'); ?></h2>
				<?php $smartsearch_informations = array_slice($smartsearch_informations, 0, $settings['information_limit']); ?>
				<?php foreach ($smartsearch_informations as $information) { ?>
					<a class="information" href="<?php echo $url_library->link('information/information', 'information_id=' . $information['information_id'] . $search_phrase); ?>">
						<?php echo $information['name']; ?>
					</a>
				<?php } ?>
			</div>
		<?php } ?>
		
		<?php if ($page_type == 'manufacturer' && !empty($smartsearch_manufacturers)) { ?>
			<div id="manufacturer-results" class="smartsearch-pro" <?php if (isset($sorting['manufacturer'])) echo 'style="display: none"'; ?>>
				<h2><?php echo html_entity_decode($settings['manufacturer_heading_' . $language_code], ENT_QUOTES, 'UTF-8'); ?></h2>
				<?php $smartsearch_manufacturers = array_slice($smartsearch_manufacturers, 0, $settings['manufacturer_limit']); ?>
				<?php foreach ($smartsearch_manufacturers as $manufacturer) { ?>
					<?php $link_route = ($settings['manufacturer_from_products']) ? 'product/search' : 'product/manufacturer/info'; ?>
					<a class="manufacturer" href="<?php echo $url_library->link($link_route, 'manufacturer_id=' . $manufacturer['manufacturer_id'] . $search_phrase); ?>">
						<?php if ($settings['manufacturer_image_width']) { ?>
							<img src="<?php echo $tool_image->resize(!empty($manufacturer['image']) ? $manufacturer['image'] : 'placeholder.png', $settings['manufacturer_image_width'] * 2, $settings['manufacturer_image_height'] * 2); ?>" />
							<br>
						<?php } ?>
						<?php echo $manufacturer['name']; ?>
					</a>
				<?php } ?>
			</div>
		<?php } ?>
		
	<?php } ?>
</div>

<?php if (!empty($sorting)) { ?>
	<script>
		$(document).ready(function(){
			<?php if (version_compare(VERSION, '4.0', '<')) { ?>
				var bottomElement = $('.col-sm-6.text-right').parent();
			<?php } else { ?>
				var bottomElement = $('.col-sm-6.text-end').parent();
			<?php } ?>
			
			<?php foreach ($sorting as $sort_order => $page_type) { ?>
				<?php if ((int)$sort_order > (int)$settings['product_sort_order']) { ?>
					$('#<?php echo $page_type; ?>-results').insertAfter(bottomElement).css('margin-top', '50px').show();
					bottomElement = $('#<?php echo $page_type; ?>-results');
				<?php } ?>
			<?php } ?>
		});
	</script>
<?php } ?>
