/* A1-WooBay - Freemius Account Page "Free Trial" Button
 * Injects a Free Trial button next to Freemius's own upgrade link.
 */
(function($) {
	'use strict';

	function injectTrialBtn() {
		var $upgrade = $('a[href*="a1woobay-settings-pricing"]').last();
		if ( $upgrade.length && ! $('#a1wb-trial-btn').length ) {
			var $btn = $('<a/>', {
				id:    'a1wb-trial-btn',
				href:  a1woobayTrial.trialUrl,
				text:  'Free Trial',
				'class': 'button',
			}).css({
				marginLeft:      '8px',
				backgroundColor: '#46b450',
				borderColor:     '#3b9e44',
				color:           '#fff',
				textShadow:      'none',
			});
			$upgrade.after( $btn );
		}
	}

	// Inject immediately + watch for Freemius dynamic content
	$(document).ready( injectTrialBtn );
	var _obs = new MutationObserver( injectTrialBtn );
	_obs.observe( document.body, { childList: true, subtree: true } );
	setTimeout( function() { _obs.disconnect(); }, 15000 );
}(jQuery));
