( function () {
	'use strict';

	document.addEventListener( 'DOMContentLoaded', function () {
		var wrap = document.getElementById( 'ambh-campaign-data' );
		if ( ! wrap ) {
			return;
		}

		wrap.querySelectorAll( '.ambh-campaign-tab a' ).forEach( function ( link ) {
			link.addEventListener( 'click', function ( e ) {
				e.preventDefault();

				var targetId = this.getAttribute( 'href' ).substring( 1 );

				wrap.querySelectorAll( '.ambh-campaign-tab' ).forEach( function ( t ) {
					t.classList.remove( 'active' );
				} );
				wrap.querySelectorAll( '.ambh-campaign-tab-panel' ).forEach( function ( p ) {
					p.classList.remove( 'active' );
				} );

				this.closest( '.ambh-campaign-tab' ).classList.add( 'active' );
				var panel = document.getElementById( targetId );
				if ( panel ) {
					panel.classList.add( 'active' );
				}
			} );
		} );
	} );
} )();
