<template>
  <el-card shadow="never">
    <template #header>
      <div style="display:flex;justify-content:space-between;align-items:center;">
        <span>智能报告推送</span>
        <el-button 
          type="primary" 
          :loading="submitting" 
          @click="onResearch"
        >
          推送报告
        </el-button>
      </div>
    </template>

    <!-- 成功提示 -->
    <div v-if="showSuccess" style="margin-top: 20px; padding: 16px; background: #f5f7fa; border-radius: 4px;">
      <el-result
        icon="success"
        title="报告已发送至您的邮箱"
      />
    </div>

    <!-- 初始状态提示 -->
    <el-empty v-else description="点击按钮开始生成报告" />

  </el-card>
</template>

<script>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { reportPushAPI } from '../api/services'

export default {
  name: 'ReportPush',
  setup() {
    const submitting = ref(false)
    const showSuccess = ref(false)

    const onResearch = async () => {
      if (submitting.value) return

      submitting.value = true
      try {
        await reportPushAPI.researchCategory()
        showSuccess.value = true
        ElMessage.success('报告已发送至您的邮箱')
      } catch (e) {
        ElMessage.error('请求失败，请稍后重试')
      } finally {
        submitting.value = false
      }
    }

    return { 
      submitting, 
      showSuccess,
      onResearch 
    }
  }
}
</script>

<style scoped>
.el-empty {
  padding: 40px 0;
}
</style>