<template>
  <section class="filter-section">
    <div class="section-header">
      <div class="header-left">
       <img src="../assets/fitller.svg" />
        <h2 class="section-title text-title-3-bold">核心相似度维度筛选</h2>
      </div>
      <button class="btn-outline" @click="emit('setAsCurrent')">设置为当前提案</button>
    </div>
    <div class="divider" />
    <div class="fields-grid">
      <div
        v-for="field in fields"
        :key="field.id"
        class="field-item"
      >
        <div class="field-label-wrapper">
          <span class="field-label text-tip-1 text-primary-65-clor">{{ field.label }}</span>
        </div>
        <div class="field-content">
          <FilterSelect
            :options="field.options"
            :model-value="field.selectedValues"
            @update:model-value="(val) => handleFieldUpdate(field.id, val)"
          />
          <div v-if="field.hint" class="field-hint">
           <img src="../assets/importent.svg" />
            <span class="text-tip-2 text-primary-50-clor">{{ field.hint }}</span>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<script setup lang="ts">
import type { FilterField } from '../api'
import FilterSelect from './FilterSelect.vue'

const props = defineProps<{
  fields: FilterField[]
}>()

const emit = defineEmits<{
  'update:fields': [fields: FilterField[]]
  setAsCurrent: []
}>()

// 更新字段选中值
function handleFieldUpdate(fieldId: string, newValues: string[]) {
  const updatedFields = props.fields.map(f => 
    f.id === fieldId 
      ? { ...f, selectedValues: newValues }
      : f
  )
  emit('update:fields', updatedFields)
}
</script>

<style scoped>
.filter-section {
  margin-top: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-icon {
  width: 16px;
  height: 16px;
  color: var(--text-primary-80-color);
}

.btn-outline {
  padding: 6px 16px;
  border: 1px solid var(--bg-black-10);
  border-radius: var(--radius-4);
  background-color: var(--bg-white-100);
  font-size: 14px;
  color: var(--text-primary-80-color);
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-outline:hover {
  background-color: var(--bg-black-2);
}

.divider {
  height: 1px;
  background-color: var(--border-black-5);
  margin-bottom: 24px;
}

.fields-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px 24px;
  padding-left: 30px;
}

.field-item {
  width: 580px;
  display: flex;
  align-items: flex-start;
}

.field-label-wrapper {
  padding-top: 4px;
}

.field-label {
  display: block;
  width: 150px;
}

.field-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-hint {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-primary-50-color);
}
</style>
