<template>
  <div class="table_search_bar flex  flex-align-center flex-justify-between">
    <div class="search_preset flex ">
      <div
        class="preset_item gallery_btn white"
        v-for="item in buttonList"
        :class="{ active:  searchParams.currentPreset === item.value }"
        :key="item.value"
        @click="handleButtonClick(item.value)"
      >
        {{ item.label }}
      </div>
    </div>
    <div class="search_input flex flex-align-center" :style="{ width: inputWidth }">
      <input
        class="search_input_inner"
        v-model="searchParams.searchText"
        :bordered="false"
        @keydown.enter="handleSearch"
        :placeholder="placeholder"
      />
      <SearchOutlined class="search_input_icon" @click="handleSearch" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import { SearchOutlined } from '@ant-design/icons-vue'

interface ButtonItem {
  label: string
  value: string
}

interface Props {
  buttonList: ButtonItem[]
  placeholder?: string
  inputWidth?: string
}

interface SearchParams {
  searchText: string
  currentPreset: string
}

interface Emits {
  (e: 'search', params: SearchParams): void
}

const props = withDefaults(defineProps<Props>(), {
  placeholder: 'batchGeneration.Search'
})

const emit = defineEmits<Emits>()

// 内部状态管理
const searchParams = reactive({
  searchText: '',
  currentPreset:props.buttonList[0]?.value || ''
})

// 处理按钮点击
const handleButtonClick = (value: string) => {
  searchParams.currentPreset = value
  handleSearch()
}

// 处理搜索
const handleSearch = () => {
  emit('search', searchParams)
}
</script>

<style lang="less" scoped>
.flex {
  display: flex;
}
.flex-1 {
  flex: 1;
}
.flex-justify-between {
  justify-content: space-between;
}
.flex-align-center {
  align-items: center;
}
.table_search_bar {
  .search_preset {
    column-gap: 2rem;
    .preset_item {
      line-height: 4rem;
      min-width: 10rem;
      font-weight: normal;
      border-width: 0.1rem;
    }
  }

  .search_input {
    height: 4rem;
    width: 23rem; // 默认宽度
    background-color: #fff;
    border: 0.1rem solid #000;
    border-radius: 43rem;
    // column-gap: 3rem;
    padding-right: 1rem;
    .search_input_inner {
      border: none;
      height: 100%;
      padding-left: 3rem;
      border-radius: 4rem;
      width: calc(100% - 2rem);
    }
    .search_input_icon {
      font-size: 2rem;
    }
  }
}
</style>
