/**
 * @file assets/js/mbs-front-core.js
 * MBS namespace bootstrap and module registry.
 *
 * Declares window.MBS, provides MBS.register() for module self-registration,
 * and runs MBS.init() on jQuery ready. Each module file calls MBS.register()
 * with its own init function; the core file never needs to change when modules
 * are added or removed.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

/* global jQuery */

( function( $, undefined ) {
	'use strict';

	/** @namespace MBS */
	var MBS = window.MBS = window.MBS || {};

	/** Internal list of registered module init functions. @type {Function[]} */
	MBS._modules = MBS._modules || [];

	/**
	 * Register a module init function to be called by MBS.init().
	 * Called once per module at module-file parse time.
	 *
	 * @param {Function} fn Module init function.
	 * @return {void}
	 */
	MBS.register = MBS.register || function( fn ) {
		if ( 'function' === typeof fn ) {
			MBS._modules.push( fn );
		}
	};

	/**
	 * Bootstrap all registered MBS front-end modules.
	 * Fires mbs:ready after all modules are initialized.
	 *
	 * @return {void}
	 */
	MBS.init = function() {
		for ( var i = 0; i < MBS._modules.length; i++ ) {
			MBS._modules[ i ]();
		}
		$( document ).trigger( 'mbs:ready' );
	};

	$( document ).ready( function() {
		MBS.init();
	} );

} )( jQuery );
