/**
 * Addons for WPBakery - Flip Container (click trigger).
 *
 * Toggles the .is-flipped class on click / Enter / Space for flip containers
 * set to the "click" trigger. Hover-triggered cards are handled purely in CSS.
 */
( function () {
	'use strict';

	function toggle( inner ) {
		inner.classList.toggle( 'is-flipped' );
	}

	function init() {
		var cards = document.querySelectorAll( '.cafw-flip--click .cafw-flip__inner' );

		cards.forEach( function ( inner ) {
			inner.addEventListener( 'click', function () {
				toggle( inner );
			} );

			inner.addEventListener( 'keydown', function ( event ) {
				if ( 'Enter' === event.key || ' ' === event.key || 'Spacebar' === event.key ) {
					event.preventDefault();
					toggle( inner );
				}
			} );
		} );
	}

	if ( 'loading' === document.readyState ) {
		document.addEventListener( 'DOMContentLoaded', init );
	} else {
		init();
	}
} )();
