import { ref, markRaw, onMounted } from 'vue'
import { start, initGlobalState } from 'qiankun'
import { useMain } from '@cip/hooks/use-main'
export default {
  setup () {
    const { setCurrentTitle } = useMain()
    console.log('subapp start')
    const actions = ref()
    onMounted(() => {
      if (!window.qiankunStarted) {
        window.qiankunStarted = true
        const state = { setCurrentTitle }
        actions.value = markRaw(initGlobalState(state))
        actions.value.onGlobalStateChange((state, prevState) => {
          console.log(state, prevState)
        })
        actions.value.setGlobalState(state)
        start({ excludeAssetFilter: () => true })
      }
    })

    return () => <div id={'subapp-viewport'}>
    </div>
  }
}
