<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <!--    <a-button-->
    <!--      v-role="'superAdmin'"-->
    <!--      type="primary"-->
    <!--      class="ele-btn-icon"-->
    <!--      @click="add"-->
    <!--    >-->
    <!--      <template #icon>-->
    <!--        <plus-outlined />-->
    <!--      </template>-->
    <!--      <span>创建应用</span>-->
    <!--    </a-button>-->
    <a-input-search
      allow-clear
      placeholder="请输入应用名称"
      v-model:value="searchText"
      @pressEnter="search"
      @search="search"
    >
      <template #addonBefore>
        <a-select v-model:value="type" style="width: 100px; margin: -5px -12px">
          <a-select-option value="appName">应用名称</a-select-option>
          <a-select-option value="appCode">应用标识</a-select-option>
        </a-select>
      </template>
    </a-input-search>
  </a-space>
</template>

<script lang="ts" setup>
  import {
    PlusOutlined,
    EditOutlined,
    SearchOutlined,
    DeleteOutlined,
    UpSquareOutlined,
    DownSquareOutlined
  } from '@ant-design/icons-vue';
  import useSearch from '@/utils/use-search';
  import type { AppParam } from '@/api/dashboard/appstore/model';
  import { ref, watch } from 'vue';
  import { assignObject } from 'ele-admin-pro';

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

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

  // 表单数据
  const { where } = useSearch<AppParam>({
    appName: '',
    appCode: ''
  });
  // 下拉选项
  const type = ref('appName');
  // 搜索内容
  const searchText = ref('');

  /* 搜索 */
  const search = () => {
    assignObject(where, {});
    if (type.value == 'appName') {
      where.appName = searchText.value;
    }
    if (type.value == 'appCode') {
      where.appCode = searchText.value;
    }
    emit('search', where);
  };

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

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

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