<template>
  <div class="hazard-container">
    <div class="hazard-header">
      <h2>安全隐患检测</h2>
      <p class="sub-title">上传现场照片或填写隐患描述，AI智能识别安全隐患</p>
    </div>
    <div class="hazard-content">
      <div class="form-section">
        <div class="form-group">
          <label>隐患类型</label>
          <select v-model="formData.type">
            <option value="">请选择隐患类型</option>
            <option v-for="type in hazardTypes" :key="type" :value="type">{{ type }}</option>
          </select>
        </div>
        <div class="form-group">
          <label>隐患描述</label>
          <textarea 
            v-model="formData.description" 
            placeholder="请详细描述发现的安全隐患..."
            rows="4"
          ></textarea>
        </div>
        <div class="form-group">
          <label>现场照片（可选）</label>
          <div class="upload-area" @click="triggerUpload">
            <span class="upload-icon">📷</span>
            <span>点击上传照片</span>
          </div>
        </div>
        <button @click="submitHazard" :disabled="isSubmitting" class="submit-btn">
          {{ isSubmitting ? '分析中...' : '提交分析' }}
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { getHazardTypes } from '@/mock/hazardMock'

const router = useRouter()

const formData = ref({
  type: '',
  description: '',
  photos: []
})

const hazardTypes = ref(getHazardTypes())
const isSubmitting = ref(false)

const triggerUpload = () => {
  // Mock upload
}

const submitHazard = async () => {
  if (!formData.value.type || !formData.value.description) {
    alert('请填写完整的隐患信息')
    return
  }
  isSubmitting.value = true
  setTimeout(() => {
    isSubmitting.value = false
    router.push('/tips-report')
  }, 1500)
}
</script>

<style scoped lang="scss">
.hazard-container {
  height: 100%;
  background: #f8f9fa;
  overflow-y: auto;
  padding: 24px;
}

.hazard-header {
  margin-bottom: 24px;

  h2 {
    font-size: 20px;
    color: #333;
    margin-bottom: 8px;
  }

  .sub-title {
    color: #666;
    font-size: 14px;
  }
}

.hazard-content {
  max-width: 600px;
  margin: 0 auto;
}

.form-section {
  background: #fff;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.form-group {
  margin-bottom: 20px;

  label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #333;
  }

  select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 8px;
    font-size: 14px;
    outline: none;

    &:focus {
      border-color: #1890ff;
    }
  }
}

.upload-area {
  border: 2px dashed #d9d9d9;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;

  &:hover {
    border-color: #1890ff;
  }

  .upload-icon {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
  }
}

.submit-btn {
  width: 100%;
  padding: 12px;
  background: #1890ff;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;

  &:hover:not(:disabled) {
    background: #40a9ff;
  }

  &:disabled {
    background: #d9d9d9;
    cursor: not-allowed;
  }
}
</style>
