

<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  import Chat from '@/views/ai/chat/new-chat/Chat.vue';
  import { getMessages } from '@/api/new-ai/chat';
  import { useChatStore } from '@/views/ai/chat/new-chat/store/useChatStore';
  import { useUserStore } from '@/store/modules/user';
  import Header from './Header.vue';

  const loading = ref(true);
  const chatStore = useChatStore();
  const userStore = useUserStore();

  onMounted(async () => {
    await fetch();
  });

  async function fetch() {
    loading.value = true;
    chatStore.conversationId = userStore.user.id;
    chatStore.messages = await getMessages(userStore.user.id);
    loading.value = false;
  }
</script>

<template>
  <div class="p-4 pt-1 chat-card w-full h-full bg-white rounded-xl shadow-xl pt-20px">
    <Header title="AI聊天助手" @reload="fetch" />
    <main ref="contentRef" class="flex-1 overflow-hidden overflow-y-auto">
        <Chat />
      </main>
  </div>
</template>

<style lang="scss" scoped>
  :v-deep(.n-tabs.n-tabs--top .n-tab-pane) {
    padding: 0 !important;
  }
  .chat-card {
    box-sizing: border-box;
    height: calc(100vh - var(--top-tool-height) - var(--tags-view-height) - var(--app-footer-height) - (var(--app-content-padding) * 3)) !important;
    main {
      height: calc(100% - 60px);
    }
  }
</style>
