/**
 * Scroll to wp-admin profile password fields (reveals hidden pass1 when needed).
 */
( function () {
	'use strict';

	document.addEventListener( 'click', function ( event ) {
		var link = event.target.closest( '.wpps-social-goto-password' );
		if ( ! link ) {
			return;
		}
		event.preventDefault();

		var generate = document.querySelector( '.wp-generate-pw' );
		if ( generate && typeof generate.click === 'function' ) {
			generate.click();
		}

		var pass1 = document.getElementById( 'pass1' );
		if ( pass1 ) {
			pass1.focus( { preventScroll: false } );
			pass1.scrollIntoView( { behavior: 'smooth', block: 'center' } );
			return;
		}

		var fallback = document.getElementById( 'password' );
		if ( fallback ) {
			fallback.scrollIntoView( { behavior: 'smooth', block: 'start' } );
		}
	} );
}() );
