Source: components/navigation/product-nav/_product-nav.js

'use strict';

/**
 * Product navigation component.
 * @namespace productNav
 * @memberof UCASDesignFramework
 * @param {object} global - UCASDesignFramework object.
 * @param {object} _u - UCASUtilities object.
 */
(function (global, _u) {
  var initialised = false // @todo DF-1231
  var productNav
  var id = 'product-nav'

  /**
   * @function init
   * @memberof! UCASDesignFramework.productNav
   * @returns {Boolean} - true for success
   * @example
   * UCASDesignFramework.productNav.init()
   */
  function init () {
    if (initialised) { return false }

    // Initialise product navigation menu.
    productNav = document.getElementById(id)

    if (!productNav) {
      _u.log.info('Failed to find product navigation menu')
      return false
    } else {
      _u.overflowMenu.create(productNav.id)
      productNav.setAttribute('data-initialised', 'true')
    }

    initialised = true
    return true
  }

  /**
   * @function destroy
   * @memberof! UCASDesignFramework.productNav
   * @example
   * UCASDesignFramework.productNav.destroy()
   */
  function destroy () {
    _u.overflowMenu.destroy(id)
    initialised = false
    productNav.setAttribute('data-initialised', 'false')
  }

  // Expose public methods and properties.
  global.productNav = {
    addSubscriptions: true,
    init: init,
    initOnLoad: true,
    destroy: destroy
  }
})(UCASDesignFramework, UCASUtilities)