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

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

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

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.ipaddr" placeholder="请输入登录地址" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="用户名称" class="pr-24px">
        <NInput v-model:value="model.userName" placeholder="请输入用户名称" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="登录状态" class="pr-24px">
        <NSelect
          v-model:value="model.status"
          placeholder="登录状态"
          value-field="dictValue"
          label-field="dictLabel"
          :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>
