<template>
  <LayoutContainer>
    <UiLoadingPanel v-if="pending" />
    <div v-else>
      <h2>{{ $t("new_education_timing")}}</h2>
      <UiForm
        ref="form"
        :model="EducationTiming"
        :entity="education_timings"
        :submitActions="submitActions"
      >
        <v-container :fluid="true" class="container">
          <v-row>
            <v-col cols="12" sm="6"> </v-col>
          </v-row>
          <v-row>
            <v-col cols="12" sm="6">
              <UiInputNumber
                v-model="education_timings.timing"
                field="new_education_timings"
                :rules="rules()"
              />
            </v-col>
          </v-row>
        </v-container>
      </UiForm>
    </div>
  </LayoutContainer>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { AnyJson } from '~/types/data'
import { SUBMIT_TYPE } from '~/types/enum/enums'
import EducationTiming from '~/models/Education/EducationTiming'
import { useI18n } from 'vue-i18n'
import { useEntityManager } from '~/composables/data/useEntityManager'

const i18n = useI18n()

const { em } = useEntityManager()

const education_timings = ref(
  em.newInstance(EducationTiming) as EducationTiming
)

const goBackRoute = { path: `/parameters`, query: { tab: 'educationTimings' } }

const submitActions = computed(() => {
  let actions: AnyJson = {}
  actions[SUBMIT_TYPE.SAVE_AND_BACK] = goBackRoute
  return actions
})

const rules = () => [
  (timing: number ) =>
    (timing !== null && timing > 0) || i18n.t('please_enter_a_value'),
]
</script>
