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

import { activateTab, onTabActivation } from './components/tabs';
import { createTooltipPopover } from './components/tooltip-popover';
import { Header, onHeaderResize } from './modules/header';
import { onHeaderBarStateChange } from './modules/header-bar';
import { highlightCode } from './helpers/highlight-code';
import { afterDomReady } from './helpers/after-dom-ready';
import { throttle } from './helpers/throttle';
import { fetchStylesheet } from './helpers/fetch-stylesheet';
import { randomId } from './helpers/random-id';
import { scrollToHash } from './helpers/scroll-to-hash';
import { formatHtml } from './helpers/format-html';
import { injectScript, injectScriptsInParallel } from './helpers/inject-script';
import { injectStylesheet } from './helpers/inject-stylesheet';
import { injectResourcePreload } from './helpers/inject-resource-preload';
import { onDropdownSelection, selectDropdownItem } from './components/dropdown';

window.umberto = {
	// The `VERSION` value will be replaced by the `DefinePlugin` webpack plugin.
	version: VERSION, // eslint-disable-line no-undef

	// Tooltips public API
	Tooltip: {
		create: createTooltipPopover
	},

	// Tabs public API
	Tabs: {
		activateTab,
		onTabActivation
	},

	// Header public API
	Header: {
		get the() { return Header.the; },
		onResize: onHeaderResize
	},

	// HeaderBar public API
	HeaderBar: {
		onStateChange: onHeaderBarStateChange
	},

	// Dropdown public API
	Dropdown: {
		selectItem: selectDropdownItem,
		onSelectChange: onDropdownSelection
	},

	// General helpers
	highlightCode,
	afterDomReady,
	throttle,
	fetchStylesheet,
	randomId,
	scrollToHash,
	formatHtml,
	injectScript,
	injectScriptsInParallel,
	injectStylesheet,
	injectResourcePreload,

	// callbacks queue that will be executed after mounting all umberto components
	afterReady( callback ) {
		if ( !this._afterReadyCallbacks ) {
			this._afterReadyCallbacks = [];
		}

		this._afterReadyCallbacks.push( callback );
	}
};
