<script setup lang="ts">
import AppEditor from '@/components/base/AppEditor.vue'
import { updateImprovementPlan } from '../api'
import { ElMessage } from 'element-plus'

const props = defineProps<{ id: string; content?: string }>()

const dialogVisible = ref<boolean>(false)

const text = ref<string>(props.content || '')

async function handleSubmit() {
  await updateImprovementPlan({ id: props.id, improvement_plan: text.value })
  dialogVisible.value = false
  ElMessage.success('保存成功')
}
</script>

<template>
  <el-button text type="primary" @click="dialogVisible = true">改进方案</el-button>
  <el-dialog title="改进方案" width="800px" v-model="dialogVisible" v-if="dialogVisible" append-to-body>
    <AppEditor v-model="text" />
    <template #footer>
      <el-row justify="center">
        <el-button type="primary" round auto-insert-space @click="handleSubmit">保存</el-button>
        <el-button round auto-insert-space @click="dialogVisible = false">取消</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>
