// Update search results (vanilla JS - no jQuery)
(function() {
  var resultsContainer = document.getElementById('inmo-search-results');
  if (resultsContainer) {
    resultsContainer.innerHTML = "<%= j (render 'search_results') %>";
  }

  // Update map markers if map controller exists
  var markers = <%= @map_markers.to_json.html_safe %>;
  var mapElement = document.querySelector('[data-controller~="map"]');
  if (mapElement && mapElement.mapController) {
    mapElement.mapController.updateMarkers(markers);
  }

  // Trigger custom event for Stimulus controllers to react
  document.dispatchEvent(new CustomEvent('search:updated', {
    detail: { markers: markers }
  }));
})();
