import { registerMicroApps, start } from 'qiankun';
import bus from '@/utils/bus'
import store from '@/store'
import router from '@/router'
import app from './app'


// 将bus挂载在Vue原型，保持父子应用一致
Vue.prototype.$bus = bus

const props = {
  bus,
  router,
  systemCode: store.state.systemCode
}

const apps = app.map((item, index) => {
  return {
    container: `#qiankun_${index + 1}`,
    props,
    ...item,
    activeRule: ({ pathname }) => {
      return (pathname.indexOf(item.activeRule) === 0 && pathname.indexOf(item.activeRule + 'blank') !== 0) || (item.urlArr && item.urlArr.indexOf(pathname) !== -1)
    }
  }
})

const appsblank = app.map(item => {
  return {
    container: '#qiankun_blank',
    props,
    ...item,
    name: item.name + 'BLANK',
    activeRule: item.activeRule + 'blank/'
  }
})

registerMicroApps([...appsblank, ...apps])

export default start