<script setup lang="ts">
import { ref } from 'vue';
import type { SelectOption } from 'naive-ui';
import SearchForm from '@/components/advanced/search-form.vue';

defineOptions({
  name: 'ConfigSearch',
  inheritAttrs: false
});

const dateRange = ref<[string, string] | null>(null);
const model = defineModel<Api.SystemManage.ConfigSearchParams>('model', { required: true });
withDefaults(defineProps<{ typeOptions?: Array<SelectOption> }>(), {
  typeOptions: () => []
});

function handleDate(value: [string, string]) {
  model.value.params =
    value === null
      ? []
      : {
          beginTime: value[0],
          endTime: value[1]
        };
}
</script>

<template>
  <SearchForm v-model:model="model" v-bind="$attrs" @reset-interlayer="dateRange = null">
    <template #formItem>
      <NFormItemGi span="24 s:12 m:6" label="参数名称" class="pr-24px">
        <NInput v-model:value="model.configName" placeholder="请输入参数名称" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="参数键名" class="pr-24px">
        <NInput v-model:value="model.configKey" placeholder="请输入参数键名" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="系统内置" class="pr-24px">
        <NSelect
          v-model:value="model.configType"
          placeholder="系统内置"
          value-field="dictValue"
          label-field="dictLabel"
          :options="typeOptions"
          clearable
        />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="创建时间" class="pr-24px">
        <NDatePicker
          v-model:formatted-value="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          clearable
          @update:formatted-value="handleDate"
        />
      </NFormItemGi>
    </template>
  </SearchForm>
</template>

<style scoped></style>
