<script setup lang="ts">
import { onMounted, inject, ref } from 'vue'
import { KkDaikan } from '@kankan-components/components'
import type { DaikanUserInfoType } from '@kankan-components/components'
import '@kankan-components/theme-chalk/src/tag.scss'
const __sdk: any = inject('__sdk')

const tags = ref<any>([])
const socketUrl = ref('wss://testws.4dkankan.com')
const socketUrlLib = ref(
  'https://cdn.bootcdn.net/ajax/libs/socket.io/4.5.4/socket.io.min.js'
)

const userInfo = ref<DaikanUserInfoType>({
  userId: 'test-user-2',
  roomId: 'test-roomid-1',
  avatar: '',
  nickName: '2222',
  role: 'customer',
})

onMounted(async () => {
  __sdk.TagManager.on('loaded', (data: any) =>
    __sdk.TagManager.load((tags.value = data) && tags.value)
  )
  __sdk.mount('#scene').render()
})

const handleTagview = (data: any) => {
  console.log('tag', data)
}
</script>

<template>
  <div id="scene">
    <Teleport v-if="tags.length" to=".kankan-plugins">
      <div xui_daikan_view>
        <KkDaikan
          :socket-lib="socketUrlLib"
          :user-info="userInfo"
          :socket-url="socketUrl"
        >
        </KkDaikan>
      </div>
    </Teleport>
  </div>
</template>

<style scoped>
#scene {
  width: 100vw;
  height: 100vh;
}
</style>
