(function(){'use strict';document.addEventListener('DOMContentLoaded',function(){var nativeSelect=document.getElementById('vly-category');if(!nativeSelect)return;var field=nativeSelect.closest('.vly-search-field-category');if(!field)return;var container=document.createElement('div');container.className='vly-cat-select';var trigger=document.createElement('button');trigger.type='button';trigger.className='vly-cat-select__trigger';trigger.setAttribute('aria-haspopup','listbox');trigger.setAttribute('aria-expanded','false');var valueSpan=document.createElement('span');valueSpan.className='vly-cat-select__value';var arrowSpan=document.createElement('span');arrowSpan.className='vly-cat-select__arrow';arrowSpan.innerHTML='<svg viewBox="0 0 12 8" fill="none"><path d="M1 1.5L6 6.5L11 1.5" stroke="#94a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';trigger.appendChild(valueSpan);trigger.appendChild(arrowSpan);var dropdown=document.createElement('div');dropdown.className='vly-cat-select__dropdown';var searchWrap=document.createElement('div');searchWrap.className='vly-cat-select__search';var searchInput=document.createElement('input');searchInput.type='text';searchInput.className='vly-cat-select__search-input';searchInput.placeholder='Buscar destino...';searchInput.setAttribute('autocomplete','off');searchInput.setAttribute('autocorrect','off');searchInput.setAttribute('autocapitalize','off');searchInput.setAttribute('spellcheck','false');searchWrap.appendChild(searchInput);var list=document.createElement('div');list.className='vly-cat-select__list';list.setAttribute('role','listbox');var emptyMsg=document.createElement('div');emptyMsg.className='vly-cat-select__empty';emptyMsg.textContent='No se encontraron resultados';var options=[];var nativeOptions=nativeSelect.options;for(var i=0;i<nativeOptions.length;i++){var opt=nativeOptions[i];var optEl=document.createElement('div');optEl.className='vly-cat-select__option';optEl.setAttribute('role','option');optEl.setAttribute('data-value',opt.value);optEl.textContent=opt.textContent.trim();if(opt.selected){optEl.classList.add('is-selected')}list.appendChild(optEl);options.push(optEl)}dropdown.appendChild(searchWrap);dropdown.appendChild(list);dropdown.appendChild(emptyMsg);container.appendChild(trigger);container.appendChild(dropdown);field.appendChild(container);var isOpen=false;var focusedIndex=-1;updateDisplay();function updateDisplay(){var selected=nativeSelect.options[nativeSelect.selectedIndex];if(selected){valueSpan.textContent=selected.textContent.trim();if(selected.value===''){valueSpan.classList.add('is-placeholder')}else{valueSpan.classList.remove('is-placeholder')}}}function open(){if(isOpen)return;isOpen=true;container.classList.add('is-open');trigger.setAttribute('aria-expanded','true');searchInput.value='';filterOptions('');focusedIndex=-1;setTimeout(function(){searchInput.focus({preventScroll:true})},50)}function close(){if(!isOpen)return;isOpen=false;container.classList.remove('is-open');trigger.setAttribute('aria-expanded','false');focusedIndex=-1}function selectOption(optEl){var value=optEl.getAttribute('data-value');nativeSelect.value=value;var event;try{event=new Event('change',{bubbles:true})}catch(e){event=document.createEvent('Event');event.initEvent('change',true,true)}nativeSelect.dispatchEvent(event);options.forEach(function(o){o.classList.remove('is-selected')});optEl.classList.add('is-selected');updateDisplay();close()}function filterOptions(query){var q=query.toLowerCase().trim();var visibleCount=0;var qNorm=removeAccents(q);options.forEach(function(optEl){var text=optEl.textContent.toLowerCase();var textNorm=removeAccents(text);if(!q||textNorm.indexOf(qNorm)!==-1){optEl.classList.remove('is-hidden');visibleCount++}else{optEl.classList.add('is-hidden');optEl.classList.remove('is-focused')}});if(visibleCount===0){emptyMsg.classList.add('is-visible')}else{emptyMsg.classList.remove('is-visible')}focusedIndex=-1}function removeAccents(str){if(String.prototype.normalize){return str.normalize('NFD').replace(/[\u0300-\u036f]/g,'')}return str}function getVisibleOptions(){return options.filter(function(o){return!o.classList.contains('is-hidden')})}function setFocused(index){var visible=getVisibleOptions();visible.forEach(function(o){o.classList.remove('is-focused')});if(index>=0&&index<visible.length){focusedIndex=index;visible[index].classList.add('is-focused');visible[index].scrollIntoView({block:'nearest'})}}trigger.addEventListener('click',function(e){e.preventDefault();e.stopPropagation();if(isOpen){close()}else{open()}});list.addEventListener('click',function(e){var optEl=e.target.closest('.vly-cat-select__option');if(optEl&&!optEl.classList.contains('is-hidden')){selectOption(optEl)}});list.addEventListener('touchend',function(e){var optEl=e.target.closest('.vly-cat-select__option');if(optEl&&!optEl.classList.contains('is-hidden')){e.preventDefault();selectOption(optEl)}});searchInput.addEventListener('input',function(){filterOptions(this.value)});searchInput.addEventListener('keydown',function(e){var visible=getVisibleOptions();if(e.key==='ArrowDown'||e.keyCode===40){e.preventDefault();var next=focusedIndex+1;if(next<visible.length){setFocused(next)}}else if(e.key==='ArrowUp'||e.keyCode===38){e.preventDefault();var prev=focusedIndex-1;if(prev>=0){setFocused(prev)}}else if(e.key==='Enter'||e.keyCode===13){e.preventDefault();if(focusedIndex>=0&&focusedIndex<visible.length){selectOption(visible[focusedIndex])}}else if(e.key==='Escape'||e.keyCode===27){close();trigger.focus()}});trigger.addEventListener('keydown',function(e){if(e.key==='Enter'||e.keyCode===13||e.key===' '||e.keyCode===32||e.key==='ArrowDown'||e.keyCode===40){e.preventDefault();open()}});document.addEventListener('click',function(e){if(isOpen&&!container.contains(e.target)){close()}});document.addEventListener('touchstart',function(e){if(isOpen&&!container.contains(e.target)){close()}},{passive:true});nativeSelect.addEventListener('change',function(){updateDisplay();var val=nativeSelect.value;options.forEach(function(o){o.classList.remove('is-selected');if(o.getAttribute('data-value')===val){o.classList.add('is-selected')}})});var form=nativeSelect.closest('form');if(form){form.addEventListener('reset',function(){setTimeout(function(){updateDisplay();options.forEach(function(o){o.classList.remove('is-selected')});if(options[0]){options[0].classList.add('is-selected')}},10)})}container.vlyCatReset=function(){nativeSelect.selectedIndex=0;nativeSelect.dispatchEvent(new Event('change',{bubbles:true}))}})})();