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

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

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

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.jobName" placeholder="请输入任务名称" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="任务组名" class="pr-24px">
        <NSelect v-model:value="model.jobGroup" placeholder="请选择任务组名" :options="jobGroupOptions" clearable />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="任务状态" class="pr-24px">
        <NSelect
          v-model:value="model.status"
          label-field="dictLabel"
          value-field="dictValue"
          placeholder="请选择任务状态"
          :options="statusOptions"
          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>
