<template>
  <section class="filters" :class="{ compact }" aria-label="筛选条件">
    <template v-if="!compact">
      <label>
      <span>法人主体</span>
      <select v-model="filters.entity">
        <option>全部主体</option>
        <option>Northstar China Ltd.</option>
        <option>Northstar Singapore Pte.</option>
        <option>Northstar US Inc.</option>
      </select>
    </label>
    <label>
      <span>费用类型</span>
      <select v-model="filters.category">
        <option>全部费用</option>
        <option>机票</option>
        <option>酒店</option>
        <option>火车/用车</option>
        <option>餐补及杂费</option>
      </select>
    </label>
    <label>
      <span>风险等级</span>
      <select v-model="filters.risk">
        <option>全部风险</option>
        <option>高风险</option>
        <option>需解释</option>
        <option>低风险</option>
      </select>
      </label>
    </template>
    <div class="segmented-wrap" :class="{ compact }">
      <span v-if="!compact">时间范围</span>
      <div class="segmented" role="tablist" aria-label="处理视图">
        <button
          v-for="range in ranges"
          :key="range"
          :class="{ active: activeRange === range }"
          type="button"
          @click="emit('update:activeRange', range)"
        >
          {{ range }}
        </button>
      </div>
    </div>
  </section>
</template>

<script setup>
defineProps({
  filters: { type: Object, required: true },
  ranges: { type: Array, required: true },
  activeRange: { type: String, required: true },
  compact: { type: Boolean, default: false }
})

const emit = defineEmits(['update:activeRange'])
</script>

<style scoped>
.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  gap: 14px;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.filters.compact {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px;
}

.filters label,
.segmented-wrap {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filters select {
  height: 40px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.segmented-wrap {
  justify-self: end;
}

.segmented {
  align-self: end;
  display: inline-flex;
  gap: 0;
  min-height: 40px;
  padding: 3px;
  border-radius: 10px;
  background: #f1f5f9;
}

.segmented button {
  position: relative;
  min-height: 34px;
  padding: 0 20px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.segmented button:hover:not(.active) {
  color: #334155;
  background: rgba(255, 255, 255, 0.5);
}

.segmented button.active {
  background: #fff;
  color: #1e293b;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (max-width: 980px) {
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented-wrap {
    justify-self: start;
  }
}

@media (max-width: 760px) {
  .filters {
    grid-template-columns: 1fr;
    padding: 0 16px 16px;
  }

  .segmented {
    width: 100%;
  }
}
</style>
