// include LWC's shadowDom polyfill
import '@lwc/synthetic-shadow';

import { assert as talonAssert } from 'talon/utils';
import { register } from 'lwc';
import * as configProvider from 'talon/configProvider';
import * as talonAura from 'talon/aura';
import * as transport from 'talon/transport';
import * as wireService from '@lwc/wire-service';
import App from 'talon/app';
import auraInstrumentation from 'talon/auraInstrumentation';
import auraStorage from 'talon/auraStorage';
import brandingService from 'talon/brandingService';
import componentService from 'talon/componentService';
import moduleRegistry from 'talon/moduleRegistry';
import RouterContainer from 'talon/routerContainer';
import RouterLink from 'universal_container/routerLink';
import routingService from 'talon/routingService';
import talonLogger from 'talon/logger';
import themeService from 'talon/themeService';
import sessionService from 'talon/sessionService';
import lightningNavigation from 'universal_container/lightningNavigation';

// Register compat modules
if (process.env.LWC_TARGET === 'es5' && self.TalonCompat && self.TalonCompat.modules) {
    moduleRegistry.addModules(self.TalonCompat.modules);
}

/*
 * Register framework modules available to templates modules
 */
moduleRegistry.addModules({
    assert: talonAssert,
    'aura-instrumentation': auraInstrumentation,
    'aura-storage': auraStorage,
    aura: talonAura,
    'talon/app': App,
    'talon/configProvider': configProvider,
    'talon/routerContainer': RouterContainer,
    'universal_container/routerLink': RouterLink,
    'talon/routingService': routingService,
    'talon/componentService': componentService,
    'instrumentation/service': auraInstrumentation,
    'lightning/configProvider': configProvider,
    'lightning/navigation': lightningNavigation,
    logger: talonLogger,
    transport,
    'wire-service': wireService,
});

/*
 * Register wire service
 */
wireService.registerWireService(register);

/*
 * Export services accessible globally e.g. Talon.componentService, etc...
 */
export default {
    componentService,
    routingService,
    themeService,
    brandingService,
    sessionService,
    configProvider,
    moduleRegistry,
};
