<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>
        <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>
      </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', data: any): void;
  }>();
  const handleSearch = () => {
    emit('update:searchData', props.searchData);
  };
  const handleReset = () => {
    for (const key in props.searchData) {
      props.searchData[key] = '';
    }
    emit('update:searchData', props.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: 10cpx;
    &--item {
      @include flex-center;
      white-space: nowrap;
      gap: 10cpx;
    }
    span {
      color: rgba(0, 0, 0, 0.85);
      font-size: 14cpx;
    }
    .el-select {
      width: 200cpx;
    }
  }
  .search-btn {
    display: flex;
  }
</style>
