document.addEventListener('DOMContentLoaded', function () {
var stars = document.querySelectorAll('#review_form p.stars a');
var total = stars.length;
var i = 0;
if (!total) return;
while (i !== total) {
(function (index) {
stars[index].addEventListener('click', function () {
// Convert visual index to WooCommerce rating
var ratingValue = total - index;
// Set hidden rating input
var ratingInput = document.getElementById('rating');
if (ratingInput) {
ratingInput.value = ratingValue;
}
// Update aria-checked correctly
var j = 0;
while (j !== total) {
stars[j].setAttribute(
'aria-checked',
j === index ? 'true' : 'false'
);
j++;
}
});
})(i);
i++;
}
});