<template>

  <StatusBar @go-handle="goHandle" :infos />
  <EventViews :infos />
  <HandlePop @update="goHandle" ref="popEvt" />
  <SpaceCtrl ref="spaceCtrlRef" />

</template>

<script lang='ts' setup>

import StatusBar from './StatusBar.vue'
import EventViews from './EventViews.vue'
import HandlePop from '@/views/components/HandlePop/index.vue'
import SpaceCtrl from '../SpaceCtrl/index.vue'

// 工具函数
import { bus, locate } from '@/views/3DModel/_state'

const infos = ref(null)
const popEvt = ref(null) // 事件弹窗
const viewAct = defineModel() // 模式
const spaceCtrlRef = ref(null) // 空间轴实例

// 事件处理
const goHandle = (state) => {

  if (state === 'start') {
    popEvt.value.diaOpen({ id: infos.value.id })
    return
  }

  viewAct.value = 1

}

onBeforeMount(() => {
  bus.on('event-locate', e => {
    infos.value = e
    locate.infos = e
    if(  spaceCtrlRef.value){

    spaceCtrlRef.value.setCurrent({
      tunnelx: e.tunnelId,
      milestone: e.milestone
    })
    }

  })
})

onBeforeUnmount(() => {
  locate.infos = null
  bus.emit('event-unselect', infos.value)
})

</script>

<style lang='scss' scoped>

</style>