/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

import $ from 'jquery';
import tippy from 'tippy.js';

export function enableBadgeTooltips() {
	$( '[data-badge-tooltip]' ).each( ( index, element ) => {
		tippy( element, {
			content: element.dataset.badgeTooltip,
			placement: 'right',
			duration: 150,
			animation: 'scale',
			theme: 'light-border',
			zIndex: 1
		} );
	} );
}

export function createTooltip( target, content, options ) {
	const tooltip = tippy( target, {
		content,
		...options
	} );

	const closeButton = tooltip.popper.querySelector( '.tippy-content__close-button' );

	closeButton.addEventListener( 'click', () => {
		tooltip.hide();
	} );

	target.addEventListener( 'click', () => {
		tooltip.hide();
	} );

	return tooltip;
}
