<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://aspenflooring.us/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://aspenflooring.us/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://aspenflooring.us/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
<style>
	.search-section { position: relative; }
	.floor-search-results {
		display: none;
		position: absolute;
		top: 100%;
		left: 0;
		right: 0;
		z-index: 9999;
		background: #fff;
		border-radius: 12px;
		box-shadow: 0 8px 24px rgba(0,0,0,0.15);
		margin-top: 8px;
		max-height: 400px;
		overflow-y: auto;
		text-align: left;
	}
	.floor-search-results.is-open { display: block; }
	.floor-search-result {
		display: flex;
		align-items: center;
		gap: 12px;
		padding: 10px 16px;
		text-decoration: none;
		color: #2a3b4b;
		cursor: pointer;
	}
	.floor-search-result:hover,
	.floor-search-result.is-active {
		background: #f5f6f7;
	}
	.floor-search-result img {
		width: 40px;
		height: 40px;
		object-fit: cover;
		border-radius: 6px;
		flex-shrink: 0;
		background: #eee;
	}
	.floor-search-result .fsr-title {
		font-weight: 600;
		font-size: 1.4rem;
		text-transform: uppercase;
		letter-spacing: 0.02em;
	}
	.floor-search-result .fsr-meta {
		font-size: 1.1rem;
		color: #6b7280;
	}
	.floor-search-empty {
		padding: 14px 16px;
		font-size: 1.3rem;
		color: #6b7280;
	}
</style>
<script>
jQuery(function ($) {
	var ajaxUrl = 'https://aspenflooring.us/wp-admin/admin-ajax.php';
	var debounceTimer;

	$('.search-section').each(function () {
		$(this).append('<div class="floor-search-results"></div>');
	});

	function closeAll() {
		$('.floor-search-results').removeClass('is-open').empty();
	}

	function renderResults($box, results) {
		$box.empty();
		if (!results.length) {
			$box.append('<div class="floor-search-empty">No floors found.</div>');
			$box.addClass('is-open');
			return;
		}
		results.forEach(function (r) {
			var $item = $('<a class="floor-search-result"></a>')
				.attr('href', r.url);
			if (r.thumb) {
				$item.append($('<img>').attr('src', r.thumb));
			}
			var meta = r.sku ? 'Model No.: ' + r.sku : '';
			$item.append(
				$('<div>').append(
					$('<div class="fsr-title"></div>').text(r.title),
					$('<div class="fsr-meta"></div>').text(meta)
				)
			);
			$box.append($item);
		});
		$box.addClass('is-open');
	}

	$(document).on('input', '.is-search-input', function () {
		var $input = $(this);
		var $box = $input.closest('.search-section').find('.floor-search-results');
		var term = $input.val().trim();

		clearTimeout(debounceTimer);
		if (term.length < 2) {
			$box.removeClass('is-open').empty();
			return;
		}

		debounceTimer = setTimeout(function () {
			$.getJSON(ajaxUrl, { action: 'aspen_floor_search', q: term }, function (results) {
				renderResults($box, results);
			});
		}, 250);
	});

	$(document).on('keydown', '.is-search-input', function (e) {
		var $box = $(this).closest('.search-section').find('.floor-search-results');
		var $items = $box.find('.floor-search-result');
		if (!$items.length) { return; }
		var $active = $items.filter('.is-active');

		if (e.key === 'ArrowDown') {
			e.preventDefault();
			var $next = $active.length ? $active.removeClass('is-active').next('.floor-search-result') : $items.first();
			($next.length ? $next : $items.first()).addClass('is-active');
		} else if (e.key === 'ArrowUp') {
			e.preventDefault();
			var $prev = $active.length ? $active.removeClass('is-active').prev('.floor-search-result') : $items.last();
			($prev.length ? $prev : $items.last()).addClass('is-active');
		} else if (e.key === 'Enter' && $active.length) {
			e.preventDefault();
			window.location.href = $active.attr('href');
		} else if (e.key === 'Escape') {
			closeAll();
		}
	});

	$(document).on('click', function (e) {
		if (!$(e.target).closest('.search-section').length) {
			closeAll();
		}
	});
});
</script>