<script lang="ts" setup>
import type { WordTempItem } from '@vben/common-ui';

import { onMounted, reactive, ref } from 'vue';

import { WordHistoryView, WordListView, WordWorkView } from '@vben/common-ui';

import { getChatList, sendChatflow } from '#/api';

let temp = reactive<WordTempItem>({
  id: 'baca08c1-e92b-4dc9-a445-3584803f54d4',
  name: '职业创新申报书',
});

const hitsory = ref([]);
const loading = ref(true);

const getLogs = async (appid: string) => {
  loading.value = true;
  const res = await getChatList(
    {
      appid,
    },
    {
      userId: '1562',
      lastId: '',
      sortBy: '',
      limit: '5',
    },
  );
  // const res = await getChatList({
  //   appid,
  //   limit: 5,
  //   page: 1,
  // });
  hitsory.value = res.data;
  loading.value = false;
};

function handleClick(item: WordTempItem) {
  temp = item;
}

onMounted(() => {
  getLogs(temp.id);
});
</script>

<template>
  <div class="px-5">
    <div class="mt-5 flex flex-col lg:flex-row">
      <div class="mr-4 w-full lg:w-1/4">
        <WordHistoryView
          :loading="loading"
          :items="hitsory"
          title="运行历史"
          @click="handleClick"
        />
        <WordListView title="选择模板" @click="handleClick" />
      </div>
      <div class="w-full lg:w-3/4">
        <WordWorkView :item="temp" :run-chatflow="sendChatflow" />
      </div>
    </div>
  </div>
</template>
