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

import $ from 'jquery';

export default function sampleCode() {
	const headerHeight = document.querySelector( 'header.top' ).offsetHeight;

	// Accordion toggling button.
	$( '.sdk-sample-source-code__button' ).on( 'click', function( e ) {
		e.preventDefault();

		$( this ).toggleClass( 'active' );
		$( this ).parent().find( '.sdk-sample-source-code__code-block' ).toggleClass( 'active' );

		// scroll smoothly to the clicked content
		$( 'html, body' ).animate( {
			scrollTop: $( this ).offset().top - headerHeight - 20
		}, 400 );
	} );
}
