<script setup lang="ts">
import type { SelectOption } from 'naive-ui';
import { $t } from '@/locales';
import { specialEnableStatusOptions } from '@/constants/business';
import { translateOptions } from '@/utils/common';

defineOptions({
  name: 'DataSearch'
});

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const model = defineModel<Api.SystemManage.DictInfoSearchParams>('model', { required: true });

defineProps<{ dictOptions: SelectOption[] }>();

function reset() {
  emit('reset');
}

function search() {
  emit('search');
}
</script>

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse :default-expanded-names="['data-search']">
      <NCollapseItem :title="$t('common.search')" name="data-search">
        <NForm :model="model" label-placement="left" :label-width="80">
          <NGrid responsive="screen" item-responsive>
            <NFormItemGi span="24 s:12 m:6" label="字典类型" path="dictType" class="pr-24px">
              <NSelect v-model:value="model.dictType" placeholder="请选择字典编码" :options="dictOptions" clearable />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="字典标签" path="dictLabel" class="pr-24px">
              <NInput v-model:value="model.dictLabel" placeholder="请输入字典标签" @keyup.enter="search" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="状态" path="status" class="pr-24px">
              <NSelect
                v-model:value="model.status"
                placeholder="数据状态"
                :options="translateOptions(specialEnableStatusOptions as CommonType.Option<string>[])"
                clearable
              />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6">
              <NSpace class="w-full" justify="end">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  重置
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  搜索
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
