import {refrechDiv} from 'Global/Layout/navigation'

export const Favorite = {
	ajouterFavorisLeft: (fav) => {    	
		var titre = fav.data('titre');
		var path = fav.data('path');
		var param = fav.data('param');
		
		$.ajax({
			url: window.oxaproc.path['Ajax.Favoris.ajouterFavoris'],
			type: 'POST',
			dataType: 'html',
			data: {titre : titre, path : path, param : param},
			success: function () {
				// Use any selector
				refrechDiv(window.location.pathname, 'menu-lateral', null, 1);
			}
		});
	},
	supprimerFavorisLeft: (fav) => {
		var id = fav.data('id');
	
		$.ajax({
			url: window.oxaproc.path['Ajax.Favoris.supprimerFavoris'],
			type: 'POST',
			dataType: 'html',
			data: {id : id},
			success: function () {
				refrechDiv(window.location.pathname, 'menu-lateral', null, 1);
			}
		});
	},
    _onPageLoad: () => {
        // Fav
        $.contextMenu({
            selector: '.menu_fav_ajout', 
            items: {
                ajout: {
                    name: window.oxaproc.trad['addFavoris'], 
                    icon: "favoris",
                    callback: function(itemKey, option, e) {
                        Favorite.ajouterFavorisLeft(option.$trigger);
                    }
                },    
            },
        });
        $.contextMenu({
            selector: '.menu_fav_suppr', 
            items: {
                suppresion: {
                    name: window.oxaproc.trad['deleteFavoris'],
                    icon: "favoris",
                    callback: function(itemKey, option, e) {
                        Favorite.supprimerFavorisLeft(option.$trigger);
                    }
                },    
            },
        });
    }
}