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

/**
 * Function to toggling the ability to scrolling the body.
 *
 * @param config - Configuration object.
 * @param config.shouldBeStopped - If it set to true, the body scrolling will be stopped.
 * Otherwise, the body scrolling will be enabled.
 */
export function bodyScroll( { shouldBeStopped } ) {
	if ( shouldBeStopped ) {
		document.body.style.top = `-${ window.scrollY }px`;
		document.body.classList.add( 'u-stop-scrolling' );
	} else {
		document.body.classList.remove( 'u-stop-scrolling' );
		window.scrollTo( 0, Math.abs( Number( document.body.style.top.replace( 'px', '' ) ) ) );
		document.body.style.removeProperty( 'top' );
	}
}
