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

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

import { PptHistoryView, PptListView, PptWorkView } from '@vben/common-ui';

import { getWorkflowLog, sendWorkflow } from '#/api';

let temp = reactive<PPTTempItem>({
  id: 'ee3889b6-50fa-463e-b956-3b93447727fc',
  name: '从可研申报书生成科技项目PPT',
});

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

const getLogs = async (appid: string) => {
  loading.value = true;
  const res = await getWorkflowLog({
    appid,
    limit: 5,
    page: 1,
  });
  hitsory.value = res.data;
  loading.value = false;
};

function handleClick(item: PPTTempItem) {
  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">
        <PptHistoryView
          :loading="loading"
          :items="hitsory"
          title="运行历史"
          @click="handleClick"
        />
        <PptListView title="选择模板" @click="handleClick" />
      </div>
      <div class="w-full lg:w-3/4">
        <PptWorkView :item="temp" :run-workflow="sendWorkflow" />
      </div>
    </div>
  </div>
</template>
