window.$ = window.$ || jQuery;

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

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

    handleMouseEnter() {
        const ratingStars = $('.wemeet-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() {
        $('.wemeet-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('wemeet-admin-dasboard-bg')) {
            wpwrap.style.backgroundColor = '#f4f7ff';
            return;
        }
        // If not found, check descendants
        const wemeetAdminDasboardBg = wpwrap ? wpwrap.querySelector('.wemeet-admin-dasboard-bg') : null;
        if (wemeetAdminDasboardBg) {
            wpwrap.style.backgroundColor = '#f4f7ff';
        }
    }
    
};

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