<script lang="ts" setup name="SearchArea">
import {
  Check,
  Delete,
  More,
  Search,
  Star,
} from '@element-plus/icons-vue'
// props参数
const props = defineProps({
  type: {
    type: String,
    default: 'default',
  }, // 显示类型，default表示正常连续显示，'seperate'表示两边分散显示
  needClear: {
    type: Boolean,
    default: false,
  }, // 是否需要重置按钮
  needSearchMore: {
    type: Boolean,
    default: false,
  }, // 是否需要高级检索
  searchMoreType: {
    type: String,
    default: 'default',
  }, // 高级检索的样式，default页面内，dialog弹窗
  size: {
    type: String,
    default: '',
  }, // 按钮及输入框大小
})
// 抛出事件
const emit = defineEmits(['search', 'clear', 'toggleMore'])
// data
const data = ref({
  searchMoreShow: false,
})

function search() {
  emit('search')
}
function clearInput() {
  emit('clear')
}
function toggleSearchMore() {
  emit('toggleMore')
  data.value.searchMoreShow = !data.value.searchMoreShow
}
function dialogSearch() {
  data.value.searchMoreShow = false
  search()
}
function dialogClearInput() {
  data.value.searchMoreShow = false
  clearInput()
}
function dialogCancel() {
  data.value.searchMoreShow = false
}
</script>

<template>
  <div class="search-div">
    <div :class="{ 'search-left': type === 'seperate', 'search-all': type === 'default' }">
      <slot />
      <el-collapse-transition>
        <div v-if="needSearchMore && searchMoreType === 'default'" v-show="data.searchMoreShow">
          <slot name="searchMore" />
        </div>
      </el-collapse-transition>
      <el-button v-if="type === 'default'" :size="size" type="primary" class="search-btn" :icon="Search" @click="search">
        搜索
      </el-button>
      <el-button v-if="type === 'default' && needSearchMore" :size="size" type="primary" class="search-btn" :icon="More" @click="toggleSearchMore">
        高级检索
      </el-button>
      <el-button v-if="type === 'default' && needClear" :size="size" type="warning" class="search-btn" :icon="Delete" @click="clearInput">
        重置
      </el-button>
      <slot name="btns" />
    </div>
    <div v-if="type === 'seperate'" class="search-right">
      <el-button :size="size" type="primary" icon="el-icon-search" class="search-btn" @click="search">
        搜索
      </el-button>
      <el-button v-if="needSearchMore" :size="size" type="primary" class="search-btn" icon="el-icon-magic-stick" @click="toggleSearchMore">
        高级检索
      </el-button>
      <el-button v-if="needClear" :size="size" type="warning" class="search-btn" icon="el-icon-delete" @click="clearInput">
        重置
      </el-button>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.search-div {
  padding: 12px;
  padding-bottom: 2px; /* 本身输入框有10px下边距 */
  padding-left: 0;
  padding-top: 2px;
  // background-color: #fff; /* Safari */
  display: flex;
  justify-content: space-between;

  .search-btn {
    margin-bottom: 10px;
  }
}

.dialog-footer {
  margin-top: 10px;
  text-align: right;
}
</style>

<style lang="scss">
.search-item + .search-btn {
  margin-left: 5px;
}
</style>
