import {
  createProvider,
  createModules,
  NodeEnv,
  autoUpdate,
  notify,
  loading,
  createAdapter,
  createServiceRequest,
  IconsPlugin
} from '@vtj/web';
import { createApp } from 'vue';
import router from './router';
import App from './App.vue';
import { name, description } from '../package.json';
import './style/index.scss';
import { createMemoryService } from './server';

const memoryService = createMemoryService();
console.log('memoryService', memoryService);

const app = createApp(App);
const adapter = createAdapter({ loading, notify });
const request = createServiceRequest(notify);
console.log('request', request);
// const service = new MemoryService(request);
// console.log('service', service);
const { provider, onReady } = createProvider({
  nodeEnv: process.env.NODE_ENV as NodeEnv,
  modules: createModules(),
  service: memoryService,
  adapter,
  router,
  dependencies: {
    Vue: () => import('vue'),
    VueRouter: () => import('vue-router')
  },
  project: {
    id: name,
    name: description
  }
});

onReady(async () => {
  app.use(router);
  app.use(provider);
  app.use(IconsPlugin);
  app.mount('#app');
});

if (process.env.NODE_ENV === 'production') {
  autoUpdate();
}
