<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <a-button type="primary" class="ele-btn-icon" @click="add">
      <template #icon>
        <plus-outlined />
      </template>
      <span>添加</span>
    </a-button>
    <a-button
      danger
      type="primary"
      class="ele-btn-icon"
      @click="removeBatch"
      :disabled="props.selection?.length === 0"
    >
      <template #icon>
        <delete-outlined />
      </template>
      <span>批量删除</span>
    </a-button>
    <a-input-search
      allow-clear
      v-model:value="where.keywords"
      placeholder="请输入关键词"
      @search="search"
      @pressEnter="search"
    />
    <a-button
      type="primary"
      style="background-color: var(--orange-6); border-color: var(--orange-5)"
      @click="openPeriod"
      >查看场馆时段</a-button
    >
  </a-space>
</template>

<script lang="ts" setup>
  import { PlusOutlined, DeleteOutlined } from '@ant-design/icons-vue';
  import useSearch from '@/utils/use-search';
  import type { FieldParam } from '@/api/booking/field/model';
  import { watch } from 'vue';

  const emit = defineEmits<{
    (e: 'search', where?: FieldParam): void;
    (e: 'add'): void;
    (e: 'remove'): void;
    (e: 'period'): void;
  }>();

  const props = defineProps<{
    // 勾选的项目
    selection?: [];
  }>();

  // 表单数据
  const { where } = useSearch<FieldParam>({
    keywords: ''
  });

  /* 搜索 */
  const search = () => {
    emit('search', where);
  };

  /*  添加 */
  const add = () => {
    emit('add');
  };

  const openPeriod = () => {
    emit('period');
  };

  // 批量删除
  const removeBatch = () => {
    emit('remove');
  };

  // 监听变化
  watch(
    () => props.selection,
    () => {}
  );
</script>
