import { watch, ref } from 'vue';
import { useRoute } from 'vue-router'
import { SubjectStructure } from '@/constants/subject'

// summary 结构类型
export default function useStructureRouter() {
  const route = useRoute()

  const currentStructure = route.query.structure === SubjectStructure.ARRANGE ? SubjectStructure.ARRANGE : SubjectStructure.RAW
  const structure = ref<SubjectStructure>(currentStructure)

  // 监听路由 query structure 参数改变
  watch(() => route.query.structure, val => {
    if (val !== SubjectStructure.ARRANGE) {
      structure.value = SubjectStructure.RAW
    } else {
      structure.value = SubjectStructure.ARRANGE
    }
  })

  return structure
}
