(function () {
  'use strict';
  const root = document.querySelector('[data-idr-root]');
  if (!root) return;

  const search = document.querySelector('[data-idr-search]');
  const status = document.querySelector('[data-idr-status]');
  const rows = Array.from(document.querySelectorAll('[data-idr-row]'));
  const visibleCount = document.querySelector('[data-idr-visible-count]');

  function applyFilters() {
    const term = (search && search.value ? search.value : '').trim().toLowerCase();
    const selectedStatus = status ? status.value : 'all';
    let shown = 0;

    rows.forEach(function (row) {
      const matchesText = !term || (row.dataset.search || '').indexOf(term) !== -1;
      const matchesStatus = selectedStatus === 'all' || row.dataset.status === selectedStatus;
      const visible = matchesText && matchesStatus;
      row.hidden = !visible;
      if (visible) shown += 1;
    });

    if (visibleCount) visibleCount.textContent = String(shown);
  }

  if (search) search.addEventListener('input', applyFilters);
  if (status) status.addEventListener('change', applyFilters);
})();
