<template>
    <Tree ref="treRef" :data="tree" />
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getFormalUserList } from '@/api/user-boot/official'
import Tree from '../cloudDevice.vue'
import { mapUserTreeNodes, selectTreeNode } from './treeCommonUtils'

const tree = ref<any[]>([])
const treRef = ref<InstanceType<typeof Tree>>()
const emit = defineEmits(['selectUser'])

async function loadTree() {
    const res: any = await getFormalUserList()
    if (res.code !== 'A0000') return

    tree.value = mapUserTreeNodes(res.data)
    const first = tree.value[0]
    if (!first) return

    emit('selectUser', first)
    await selectTreeNode(treRef.value, first)
}

loadTree()
</script>
