<template>
  <LayoutContainer>
    <UiLoadingPanel v-if="pending" />
    <UiForm
      v-else
      v-model="parameters"
    >
      <v-row>
        <v-col cols="12">
          <UiInputCheckbox
            v-model="parameters.periodValidation"
            field="periodValidation"
            label="define_validation_periods_for_teachers"
          />

          <UiInputCheckbox
            v-model="parameters.editCriteriaNotationByAdminOnly"
            field="editCriteriaNotationByAdminOnly"
            label="evaluation_criterium_edition_is_admin_only"
          />

          <UiInputCheckbox
            v-model="parameters.requiredValidation"
            field="requiredValidation"
            label="mandatory_validation_for_evaluations"
          />

          <UiInputAutocompleteWithEnum
            v-if="organizationProfile.hasModule('AdvancedEducationNotation')"
            v-model="parameters.advancedEducationNotationType"
            enum-name="advanced_education_notation"
            field="advancedEducationNotationType"
          />

          <UiInputAutocompleteWithEnum
            v-model="parameters.educationPeriodicity"
            enum-name="education_periodicity"
            field="educationPeriodicity"
          />

          <UiInputNumber
            v-model="parameters.average"
            field="average"
            label="max_note_for_pedagogical_followup"
            :default="20"
            :min="1"
            :max="100"
            class="mt-2"
          />
        </v-col>
      </v-row>
    </UiForm>
  </LayoutContainer>
</template>

<script setup lang="ts">
import type { AsyncData } from '#app'
import Parameters from '~/models/Organization/Parameters'
import { useEntityFetch } from '~/composables/data/useEntityFetch'
import { useOrganizationProfileStore } from '~/stores/organizationProfile'

definePageMeta({
  name: 'parameters_education_notation_page',
})

const { fetch } = useEntityFetch()

const organizationProfile = useOrganizationProfileStore()

if (organizationProfile.parametersId === null) {
  throw new Error('Missing organization parameters id')
}

const { data: parameters, pending } = fetch(
  Parameters,
  organizationProfile.parametersId,
) as AsyncData<Parameters | null, Error | null>
</script>

<style scoped lang="scss"></style>
