const hardwareForm = document.querySelector('#hardware-filters'); if (hardwareForm) { const cards = [...document.querySelectorAll('[data-hardware-card]')]; const count = document.querySelector('#hardware-count'); const empty = document.querySelector('#hardware-empty'); const normalize = value => value.toLocaleLowerCase('tr').replaceAll('ı', 'i').normalize('NFD').replace(/[\u0300-\u036f]/g, ''); const searchText = new Map(cards.map(card => [card, normalize(card.dataset.search)])); function filterHardware() { const query = normalize(hardwareForm.elements.q.value.trim()).split(/\s+/).filter(Boolean); const filters = ['kind', 'role', 'arch', 'budget', 'supply']; let visible = 0; for (const card of cards) { const match = filters.every(key => !hardwareForm.elements[key].value || card.dataset[key] === hardwareForm.elements[key].value) && query.every(term => searchText.get(card).includes(term)); card.hidden = !match; if (match) visible++; } count.textContent = `${visible} / ${cards.length} seçenek gösteriliyor`; empty.hidden = visible !== 0; } hardwareForm.addEventListener('submit', event => event.preventDefault()); hardwareForm.addEventListener('input', filterHardware); hardwareForm.addEventListener('change', filterHardware); hardwareForm.addEventListener('reset', () => queueMicrotask(filterHardware)); document.querySelector('[data-turkiye-filter]')?.addEventListener('click', () => { hardwareForm.reset(); hardwareForm.elements.supply.value = 'tr'; filterHardware(); }); function revealHardwareHash() { const target = document.getElementById(location.hash.slice(1)); if (target?.matches('[data-hardware-card]') && target.hidden) { hardwareForm.reset(); filterHardware(); target.scrollIntoView({ block: 'start', behavior: 'instant' }); } if (target?.matches('[data-build-id]')) { target.open = true; target.scrollIntoView({ block: 'start', behavior: 'instant' }); } } window.addEventListener('hashchange', revealHardwareHash); filterHardware(); revealHardwareHash(); }