<template>
  <div class="suggestions-page">
    <div class="page-header">
      <h1 class="page-title">建言献策</h1>
      <p class="page-desc">您的每一条建议都是我们进步的动力，期待您的声音</p>
    </div>

    <div class="suggestions-content">
      <div class="intro-section">
        <h2>参与方式</h2>
        <p>欢迎您对政策制定、经济发展、社会治理等方面提出宝贵意见和建议。请您先登录或注册账号，然后填写建言内容。</p>
      </div>

      <a-form
        v-if="isAuthed"
        :model="formData"
        :rules="rules"
        layout="vertical"
        class="suggestion-form"
      >
        <a-form-item label="建言标题" name="title">
          <a-input v-model:value="formData.title" placeholder="请输入建言标题" :maxlength="100" show-count />
        </a-form-item>

        <a-form-item label="建言内容" name="content">
          <a-textarea
            v-model:value="formData.content"
            placeholder="请详细描述您的建议和意见..."
            :rows="8"
            :maxlength="2000"
            show-count
          />
        </a-form-item>

        <a-form-item label="联系方式（选填）" name="contact">
          <a-input v-model:value="formData.contact" placeholder="请输入您的联系方式，方便我们与您联系" />
        </a-form-item>

        <a-form-item>
          <a-space>
            <a-button type="primary" size="large" @click="handleSubmit" :loading="submitting">
              提交建言
            </a-button>
            <a-button size="large" @click="handleReset">
              重置
            </a-button>
          </a-space>
        </a-form-item>
      </a-form>

      <div v-else class="login-prompt">
        <a-result
          title="请先登录"
          sub-title="登录后可提交建言献策"
        >
          <template #extra>
            <a-button type="primary" size="large" @click="navigateTo('/login')">
              去登录
            </a-button>
          </template>
        </a-result>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { message } from 'ant-design-vue'
import { getToken } from '@/utils/token-util'

useHead({ title: '建言献策 - 决策咨询网' })

const isAuthed = computed(() => !!getToken())
const submitting = ref(false)

const formData = reactive({
  title: '',
  content: '',
  contact: '',
})

const rules = {
  title: [{ required: true, message: '请输入建言标题' }],
  content: [{ required: true, message: '请输入建言内容' }],
}

async function handleSubmit() {
  try {
    // TODO: 接入实际API提交建言
    // await submitSuggestion(formData)
    message.success('建言已提交，感谢您的参与！')
    handleReset()
  } catch (e: any) {
    message.error(e?.message || '提交失败')
  }
}

function handleReset() {
  formData.title = ''
  formData.content = ''
  formData.contact = ''
}
</script>

<style scoped>
.suggestions-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  color: #1f2937;
  margin: 0 0 12px;
}

.page-desc {
  font-size: 16px;
  color: #6b7280;
  margin: 0;
}

.suggestions-content {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.intro-section {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid #f0f0f0;
}

.intro-section h2 {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 8px;
}

.intro-section p {
  font-size: 14px;
  color: #6b7280;
  margin: 0;
  line-height: 1.6;
}

.suggestion-form {
  max-width: 600px;
}

.login-prompt {
  padding: 40px 0;
}
</style>
