<template>
    <BaseIconButton :icon="icon" :title="t('邀请评价')" :disabled="!sessionId || isPending" @click="handleClick" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import AIDeskCoreInstance from '@tencentcloud/ai-desk-core';
import BaseIconButton from './BaseIconButton.vue';
import toast from '../../../../../utils/toast';
import sendEvaluateIcon from '../../../../Mobile/Chat/ChatInput/inputTools/sendEvaluate/sendEvaluateIcon.svg';
import { parseUnknownError } from '../../../../../utils/parseUnknownError.ts';

const props = defineProps<{ sessionId: string }>();
const emit = defineEmits<{ (e: 'sent'): void }>();

const { t } = useI18n();
const icon = sendEvaluateIcon;
const isPending = ref(false);

const handleClick = async () => {
    if (!props.sessionId || isPending.value) {
        return;
    }

    try {
        isPending.value = true;
        await AIDeskCoreInstance.sessionService.evaluateSession(props.sessionId);
        emit('sent');
    } catch (error) {
        console.error(error);
        toast.error(parseUnknownError(error))
    } finally {
        isPending.value = false;
    }
};
</script>
