<template>
  <DiscussionItem
    :author="author"
    :canEdit="isDeveloper || isIssueAuthor"
    :can-delete="false"
    :body="temp?.description"
    :repo-id="repoId"
    @save-content="saveDescription"
    eventIcon="gt-comment"
    :loading="loading"
    :key="key"
    :targetId="temp?.iid"
    event-msg="评论："
    @quote-reply="$emit('quote-reply',temp?.description)"
  />
</template>
<script lang="ts" setup>
defineOptions({ name: 'IssueDescript' });
import { ref, inject, watch } from 'vue';
import type { IAuthor } from '@/api/issue/types';
import DiscussionItem from '@/views/Repo/components/DiscussionItem/index.vue';
import { updateIssue } from '@/api/issue';
import { reqCatch } from '@/utils/catch';
const repoId = inject('repoId');
const issueId = inject('issueId');
const props = defineProps<{
  data: object;
  user: IAuthor;
  author: IAuthor;
}>();
defineEmits<{
  'quote-reply':[value:string]
}>();
const key = ref(0);
const loading = ref(false);
const temp = ref(props.data);
const isDeveloper = inject('isDeveloper');
const isIssueAuthor = inject('isIssueAuthor');
const saveDescription = async(str: string) => {
  loading.value = true;
  const res = await reqCatch(updateIssue, {
    project_id: repoId,
    issue_iid: issueId,
    description: str
  });
  temp.value = res?.data?.data;
  // key.value++;
  loading.value = false;
};
</script>
