// entry.esm.js

/**
 *  Automated module export and auto-install
 *  https://vuejs.org/v2/cookbook/packaging-sfc-for-npm.html
 */

import * as components from '../src/components';
import Vue from 'vue'

/**
 * Declare install function executed by Vue.use()
 * @param Vue
 */
const install = function storefrontComponents(Vue) {
    Object.entries(components).forEach(([componentName, component]) => {
        /**
         * Outputs string similar to  Vue.component('componentName', 'component)
         */
        if (install.installed) return;
        install.installed = true;
        Vue.component(componentName, component);
    });
};

/**
 * Auto-install when vue is found (eg. in browser via <script> tag)
 * @type {null}
 */
let GlobalVue = null;
if (typeof window !== 'undefined') {
    GlobalVue = window.Vue;
} else if (typeof global !== 'undefined') {
    GlobalVue = global.Vue;
}
if (GlobalVue) {
    GlobalVue.use(plugin);
}

/**
 * To allow individual component use, export components,
 * each is registered via Vue.component()
 */

//export { components, install };

// Create module definition for Vue.use()
export default install;
