<template>
  <div class="search-box">
    <section class="select-box">
      <div class="select-box--item" v-for="item in searchConfig" :key="item.prop">
        <span>{{ item.label }}</span>
        <template v-if="item.slot">
          <slot :name="item.slot" />
        </template>
        <template v-else>
          <component :is="item.component" v-model="searchData[item.prop]" v-bind="item.componentProps">
            <el-option
              v-for="option in item.selectOptions"
              :key="option.value"
              :label="option.label"
              :value="option.value"
            />
          </component>
        </template>
      </div>
    </section>
    <section class="search-btn">
      <el-button type="primary" @click="handleSearch">查询</el-button>
      <el-button @click="handleReset">重置</el-button>
    </section>
  </div>
</template>

<script lang="ts" setup>
  import type { SearchConfig } from '@/views/disaster/types';
  const props = defineProps<{
    searchConfig: SearchConfig[];
    searchData: any;
  }>();
  const emit = defineEmits<{
    (e: 'update:searchData'): void;
  }>();
  const handleSearch = () => {
    emit('update:searchData');
  };
  const handleReset = () => {
    for (const key in props.searchData) {
      props.searchData[key] = null;
    }
    emit('update:searchData');
  };
</script>

<style lang="scss" scoped>
  .search-box {
    @include flex-center;
    justify-content: space-between;
    width: 100%;
  }
  .select-box {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 32px;
    &--item {
      @include flex-center;
      white-space: nowrap;
      gap: 10px;
    }
    span {
      color: rgba(0, 0, 0, 0.85);
      font-size: 14px;
    }
    .el-select {
      width: 200px;
    }
  }
  .search-btn {
    display: flex;
  }
</style>
