<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <a-select
      v-model:value="where.type"
      placeholder="选择类型"
      allow-clear
      style="width: 120px"
      @change="search"
    >
      <a-select-option :value="0">商城分类</a-select-option>
      <a-select-option :value="1">外卖分类</a-select-option>
    </a-select>
    <a-input-search
      v-model:value="where.keywords"
      placeholder="搜索分类名称"
      allow-clear
      style="width: 200px"
      @search="search"
      @pressEnter="search"
    />
    <a-button type="primary" class="ele-btn-icon" @click="add">
      <template #icon><PlusOutlined /></template>
      <span>添加分类</span>
    </a-button>
    <a-button
      danger
      class="ele-btn-icon"
      :disabled="!selection?.length"
      @click="remove"
    >
      <template #icon><DeleteOutlined /></template>
      <span>批量删除</span>
    </a-button>
  </a-space>
</template>

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

  const props = withDefaults(
    defineProps<{
      selection?: any[];
    }>(),
    {}
  );

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

  const { where } = useSearch<ShopGoodsCategoryParam>({
    type: undefined,
    keywords: ''
  });

  const search = () => {
    emit('search', where);
  };

  const add = () => {
    emit('add');
  };

  const remove = () => {
    emit('remove');
  };
</script>
