window.$ = window.$ || jQuery;

const GoodmeetAdmin = {
    init() {
        this.bindEvents();
        this.changeBackground();
    },

    bindEvents() {
        $(document).on('mouseenter', '.goodmeet-rating .rating-wrapper .star', this.handleMouseEnter);
        $(document).on('mouseleave', '.goodmeet-rating .rating-wrapper .star', this.handleMouseLeave);
    },

    handleMouseEnter() {
        const ratingStars = $('.goodmeet-rating .rating-wrapper .star');
        const index = ratingStars.index(this);

        ratingStars.each(function(i) {
            if (i <= index) {
                $(this).addClass('filled'); // Add filled class to the hovered and previous stars
            }
        });
    },

    handleMouseLeave() {
        $('.goodmeet-rating .rating-wrapper .star').removeClass('filled'); // Remove filled class from all stars
    },

    changeBackground() {
        // Check if #wpwrap has the class directly
        const wpwrap = document.getElementById('wpwrap');
        if (wpwrap && wpwrap.classList.contains('goodmeet_admin-dasboard-bg')) {
            wpwrap.style.backgroundColor = '#f4f7ff';
            return;
        }
        // If not found, check descendants
        const goodmeetAdminDasboardBg = wpwrap ? wpwrap.querySelector('.goodmeet-admin-dasboard-bg') : null;
        if (goodmeetAdminDasboardBg) {
            wpwrap.style.backgroundColor = '#f4f7ff';
        }
    }
    
};

$(document).ready(function(){
    GoodmeetAdmin.init();
});
