<script setup lang="ts">
import { reactive } from 'vue'
import { getRemoteCsdnCommit, askGpt } from '../../service/csdnApi.js'
import { message } from 'ant-design-vue';
import Author from '../Author.vue'
const state: any = reactive({
    loading: false,
    analysis: '',
    text: '',
    articleId: '133955447',
    page: 1,
    pageSize: 10,
    unfold: '',
    commitId: ''
})

const getCommit = async () => {
    state.loading = true
    state.text = ''
    const params = { ...state }
    delete params.text
    delete params.loading
    try {
        const result = await getRemoteCsdnCommit(params)
        console.log(result, 'result')
        const { data } = result?.data
        if (data?.list) {
            state.text = data.list.map((item: any) => item.info.content).join(',')
        }
    }
    catch (e) {
        message.warning(JSON.stringify(e))
    }
    finally {
        state.loading = false
    }

}
const analysisCommit = async () => {
    state.loading = true
    try {
        console.log('state.text', state.text)
        const res = await askGpt({
            content: '帮我分析总结这些评论' + state.text
        })
        if (res?.data?.data?.result) {
            state.analysis = res?.data?.data?.result
        }
    }
    catch (e) {
        message.warn(JSON.stringify(e))
    }
    finally {
        state.loading = false
    }
}
</script>

<template>
    <Author />
    <a-spin :spinning="state.loading">
        <div style="border:1px solid #3333;padding:5px;">
            <div>
                <div style="max-width:450px;">
                    <a-row justify="space-between">
                        <a-col :span="8">
                            (文章id)articleId: <a-input v-model:value="state.articleId" placeholder="'文章id'" />
                        </a-col>
                        <a-col :span="8">
                            (页数)page: <a-input v-model:value="state.page" placeholder="页数" />
                        </a-col>
                    </a-row>

                    <a-row justify="space-between">
                        <a-col :span="8">
                            (页大小)pageSize: <a-input v-model:value="state.pageSize" placeholder="总页数" />
                        </a-col>
                        <a-col :span="8">
                            (收藏)unfold: <a-input v-model:value="state.unfold" placeholder="收藏" />
                        </a-col>
                    </a-row>

                    <a-row justify="space-between">
                        <a-col :span="8">
                            (评论id)commitId: <a-input v-model:value="state.commitId" placeholder="评论id" />
                        </a-col>
                    </a-row>
                </div>
                <div style="width:100%;margin-top:10px;display: flex;justify-content: center;align-items: center;">
                    <a-button @click="getCommit" type="primary">获取评论</a-button>
                </div>
            </div>
            <div>
                <div style="margin:10px 0;">
                    <a-tag color="blue">评论</a-tag>
                </div>
                <a-textarea v-model:value="state.text" placeholder="评论" :disabled="state.loading"
                    :auto-size="{ minRows: 2, maxRows: 20 }" />
            </div>

            <div style="margin-top:10px;;width:100%;display: flex;justify-content: center;align-items: center;">
                <a-button @click="analysisCommit" type="primary">文心一言分析评论</a-button>
            </div>
            <div style="margin-top:10px;">
                <div style="margin:10px 0;">
                    <a-tag color="blue">文心一言生成的总结</a-tag>
                </div>
                <a-textarea v-model:value="state.analysis" placeholder="生成的文章总结" readonly
                    :auto-size="{ minRows: 2, maxRows: 20 }" />
            </div>
        </div>
    </a-spin>
</template>