<script setup lang="ts">
import { toRaw } from 'vue';
import { jsonClone } from '@sa/utils';
import { useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';

defineOptions({
  name: 'HistoryScoreControlLineSearch'
});

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

const emit = defineEmits<Emits>();

const { formRef, validate, restoreValidation } = useNaiveForm();

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

const defaultModel = jsonClone(toRaw(model.value));

function resetModel() {
  Object.assign(model.value, defaultModel);
}

async function reset() {
  await restoreValidation();
  resetModel();
  emit('search');
}

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

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse>
      <NCollapseItem :title="$t('common.search')" name="art-history-score-control-line-search">
        <NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
          <NGrid responsive="screen" item-responsive>
            <NFormItemGi
              span="24 s:12 m:6"
              label="省份行政区划代码"
              label-width="auto"
              path="provinceCode"
              class="pr-24px"
            >
              <NInput v-model:value="model.provinceCode" placeholder="请输入省份行政区划代码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="省份名称" label-width="auto" path="provinceName" class="pr-24px">
              <NInput v-model:value="model.provinceName" placeholder="请输入省份名称" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="年份" label-width="auto" path="year" class="pr-24px">
              <NInput v-model:value="model.year" placeholder="请输入年份" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="专业类别" label-width="auto" path="majorCategory" class="pr-24px">
              <NInput v-model:value="model.majorCategory" placeholder="请输入专业类别" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="批次" label-width="auto" path="batchName" class="pr-24px">
              <NInput v-model:value="model.batchName" placeholder="请输入批次" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="科类(文/理)" label-width="auto" path="subjectType" class="pr-24px">
              <NSelect v-model:value="model.subjectType" placeholder="请选择科类(文/理)" :options="[]" clearable />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="文化成绩分数" label-width="auto" path="cultureScore" class="pr-24px">
              <NInput v-model:value="model.cultureScore" placeholder="请输入文化成绩分数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="专业成绩分数" label-width="auto" path="majorScore" class="pr-24px">
              <NInput v-model:value="model.majorScore" placeholder="请输入专业成绩分数" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="文化成绩校考分数"
              label-width="auto"
              path="cultureScoreExam"
              class="pr-24px"
            >
              <NInput v-model:value="model.cultureScoreExam" placeholder="请输入文化成绩校考分数" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="专业成绩校考分数"
              label-width="auto"
              path="majorScoreExam"
              class="pr-24px"
            >
              <NInput v-model:value="model.majorScoreExam" placeholder="请输入专业成绩校考分数" />
            </NFormItemGi>
            <NFormItemGi :show-feedback="false" span="24" class="pr-24px">
              <NSpace class="w-full" justify="end">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
