/*
Widget: FlyInNotificaton - JS Initialisation, Setup, Events
See detailed documentation in Dev/mediawiki
deferrable:YES -- This is basically a standalone gadget
*/

(function() {

	// Settings

	let waitInSeconds = 120; // integer
	let cookieDays = 7; // Life span of dismiss cookie, after that notification will be shown again
	let cookieName = 'flyInBannerIdDismissed';
	
	// Only for testing purposes on /wiki/TestpageForFlyInNotification
	
	let isTestpage = $('body').hasClass('page-TestpageForFlyInNotification')
	
	if( isTestpage ) {
		let altData = (varname,originalValue) => $('.fly-in-notification-data').attr("data-"+varname.toLowerCase()) || originalValue;
		waitInSeconds = parseInt( altData( 'waitInSeconds', waitInSeconds ) );
		cookieDays = parseInt( altData( 'cookieDays', cookieDays ) );
		cookieName = altData( 'cookieName', cookieName );
	}
	
	// Globals

	let panel = $('#fly-in-notification-panel');

	// Setup
	
	// If notification is disabled, stop here
	if( Cookies.get( cookieName ) && ! isTestpage ) return;

	setTimeout( function() {
		panel.css( 'display', 'block' );
		let w = panel.width();
		panel.find( '.inner-wrapper' ).css( 'width', w + 'px' );
		panel.css( 'width', 0 ).animate({ width: w }, () => panel.css( 'width', '' ));
	}, waitInSeconds * 1000 );

	// Events
	
	panel.find('.close-panel').on( 'click', function() {
		Cookies.set( cookieName, true, { expires: cookieDays, sameSite: 'strict' } );
		panel.animate( { width: 0 }, () => panel.css( { display: 'none', width: '' } ) );
	});

})();

/*
[[Category:MultiWiki]]
*/