<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: 'SchoolEnrollPlanSearch'
});

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

const emit = defineEmits<Emits>();

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

const model = defineModel<Api.Art.SchoolEnrollPlanSearchParams>('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="school-search-card card-wrapper">
    <NCollapse>
      <NCollapseItem :title="$t('common.search')" name="art-school-enroll-plan-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="学校ID" label-width="auto" path="schoolId" class="pr-24px">
              <NInput v-model:value="model.schoolId" placeholder="请输入学校ID" />
            </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="province" class="pr-24px">
              <NInput v-model:value="model.province" 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="专业ID(可选，有则填)"
              label-width="auto"
              path="majorId"
              class="pr-24px"
            >
              <NInput v-model:value="model.majorId" placeholder="请输入专业ID(可选，有则填)" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="专业名称(冗余，没专业ID也能落库)"
              label-width="auto"
              path="majorName"
              class="pr-24px"
            >
              <NInput v-model:value="model.majorName" placeholder="请输入专业名称(冗余，没专业ID也能落库)" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="学历层次：本科/专科"
              label-width="auto"
              path="educationLevel"
              class="pr-24px"
            >
              <NInput v-model:value="model.educationLevel" placeholder="请输入学历层次：本科/专科" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="计划数" label-width="auto" path="planNum" class="pr-24px">
              <NInput v-model:value="model.planNum" 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>
