<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <a-button class="ele-btn-icon" @click="add">
      <template #icon>
        <PlusOutlined />
      </template>
      <span>添加</span>
    </a-button>
    <a-button class="ele-btn-icon" @click="add">
      <span>同步会员卡权限</span>
    </a-button>
    <a-input-search
      allow-clear
      placeholder="会员卡名称"
      v-model:value="where.keywords"
      @pressEnter="search"
      @search="search"
      style="width: 360px"
    />
  </a-space>
</template>

<script lang="ts" setup>
  import { PlusOutlined } from '@ant-design/icons-vue';
  import type { GradeParam } from '@/api/user/grade/model';
  import { ref, watch } from 'vue';
  import dayjs from 'dayjs';
  import useSearch from '@/utils/use-search';
  import { BookingVipParam } from '@/api/booking/bookingVip/model';

  const props = withDefaults(
    defineProps<{
      // 选中的角色
      selection?: [];
    }>(),
    {}
  );

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

  // 表单数据
  const { where } = useSearch<BookingVipParam>({
    id: undefined,
    keywords: undefined,
    timeStart: undefined,
    timeEnd: undefined
  });

  // 日期范围选择
  const dateRange = ref<[string, string]>(['', '']);

  /* 搜索 */
  const search = () => {
    const [d1, d2] = dateRange.value ?? [];
    where.timeStart = d1 ? dayjs(d1).valueOf() / 1000 : undefined;
    where.timeEnd = d2 ? dayjs(d2).valueOf() / 1000 : undefined;
    emit('search', {
      ...where
    });
  };

  // 新增
  const add = () => {
    emit('add');
  };

  watch(
    () => props.selection,
    () => {}
  );
</script>
