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

export default function copyMobileApiNavigation() {
	// First check if it is API page.
	const apiTree = document.querySelector( '.side-navigation__inner--api' );

	if ( !apiTree ) {
		return;
	}

	// Check current project.
	const currentProject = document.querySelector( 'header.top' ).dataset.project;

	// copy there API tree
	const mobileApiMenu = document.querySelector(
		`.header__menu-rwd__projects li[ data-project=${ currentProject } ] li[ data-group=api-reference ]`
	);

	// Clone HTML Element with API Tree.
	const clonedApiTree = apiTree.firstElementChild.cloneNode( true );

	mobileApiMenu.appendChild( clonedApiTree );
}
