<script setup lang="ts">
import { useLeadForm } from '~/composables/useLeadForm'
const { form, loading, success, error, submit } = useLeadForm('contact')

const coopTypes = ['政府项目', '医院合作', '养老机构合作', '社区服务', '技术合作', '其他']
</script>

<template>
  <div class="max-w-lg mx-auto">
    <form v-if="!success" @submit.prevent="submit" class="space-y-5">
      <div class="grid sm:grid-cols-2 gap-5">
        <div>
          <label class="block text-sm font-medium mb-1 text-left">姓名 <span class="text-red-500">*</span></label>
          <input v-model="form.name" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary-50 outline-none" placeholder="您的姓名" />
        </div>
        <div>
          <label class="block text-sm font-medium mb-1 text-left">单位名称 <span class="text-red-500">*</span></label>
          <input v-model="form.orgName" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary-50 outline-none" placeholder="您所在的单位" />
        </div>
      </div>
      <div>
        <label class="block text-sm font-medium mb-1 text-left">手机号 <span class="text-red-500">*</span></label>
        <input v-model="form.phone" type="tel" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary-50 outline-none" placeholder="您的手机号" />
      </div>
      <div>
        <label class="block text-sm font-medium mb-1 text-left">合作类型</label>
        <select v-model="form.contact" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary-50 outline-none">
          <option value="">请选择</option>
          <option v-for="t in coopTypes" :key="t" :value="t">{{ t }}</option>
        </select>
      </div>
      <div>
        <label class="block text-sm font-medium mb-1 text-left">需求描述</label>
        <textarea v-model="form.message" rows="4" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary-50 outline-none resize-none" placeholder="请描述您的合作需求"></textarea>
      </div>
      <p v-if="error" class="text-red-500 text-sm">{{ error }}</p>
      <button type="submit" :disabled="loading"
        class="w-full px-6 py-3 bg-cta text-white rounded-xl font-semibold hover:bg-cta-700 transition-colors disabled:opacity-50">
        {{ loading ? '提交中...' : '提交咨询' }}
      </button>
    </form>
    <div v-else class="text-center py-12">
      <div class="w-16 h-16 mx-auto mb-4 rounded-full bg-green-100 text-green-500 flex items-center justify-center"><svg class="w-10 h-10" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M5 13l4 4L19 7" stroke-linecap="round" stroke-linejoin="round"/></svg></div>
      <h3 class="text-2xl font-bold mb-2">提交成功</h3>
      <p class="text-text-secondary">感谢您的咨询，我们将尽快与您联系。</p>
    </div>
  </div>
</template>
