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

import $ from 'jquery';
import { setupPrism } from './_prism';
import { enableCollapsables, hideTogglers } from './_collapsables';
import { enableAnchors } from './_anchors';
import { enableDropdowns } from './_dropdowns';
import { enableFiltering } from './_filtering';
import { trackArticlePosition } from './_toc';
import { expandApiTree, scrollApiTree } from './_apitree';
import { setUpFuse } from './_apisearch';
import pageNavigation from './_pagenavigation';
import { activateDevNames } from './_devnames';
import sideNavigation from './_sidenavigation';
import sampleCode from './_samplecode';
import copyMobileApiNavigation from './_copymobileapinavigation';
import { rwdButton } from './_rwdmenu';
import imageModal from './_imageModal';
import showWarningBanner from './_warningbanner';
import { enableBadgeTooltips, createTooltip } from './_tooltips';
import attachPermalinkListener from './_attachpermalinklistener';
import { createCodeSwitcherButtons } from './_codeswitcherbuttons';

// Changing documentation theme. To enable, type in the console: `localStorage.setItem( 'theme', 'theme-dark' )`.
if ( localStorage.getItem( 'theme' ) === 'theme-dark' ) {
	document.getElementsByTagName( 'html' )[ 0 ].classList.add( 'theme-dark' );
}

// Set up the global variable.
window.umberto = {
	// The `VERSION` value will be replaced by the `DefinePlugin` webpack plugin.
	version: VERSION, // eslint-disable-line no-undef
	showWarningBanner,
	createTooltip
};

// Ask the SOS team before touching this 😛
window.open.closed = 1;

$( document ).ready( () => {
	pageNavigation(); // pageNavigation - needs to be run before filtering initialization.
	copyMobileApiNavigation(); // copy API Tree into mobile navigation
	sideNavigation();
	expandApiTree();
	scrollApiTree();
	enableFiltering();
	setupPrism();
	enableCollapsables();
	hideTogglers();
	enableAnchors();
	enableDropdowns();
	trackArticlePosition();
	setUpFuse();
	activateDevNames();
	attachPermalinkListener();
	rwdButton();
	imageModal(); // lightbox for { @img } elements
	// `sampleCode()` must be called after the `setupPrism()` function.
	sampleCode(); // control accordion of sample code and buttons(copy/download)
	enableBadgeTooltips(); // attaches tippy.js tooltip for all elements with data-badge-tooltip
	createCodeSwitcherButtons();
} );
