<template>
  <NuxtLayout name="parameters">
    <LayoutContainer>
      <UiLoadingPanel v-if="pending" />
      <UiForm
          v-else
          :model="Parameters"
          :entity="parameters"
      >
        <v-row>
          <v-col cols="6">
            <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"
            />

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

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

            <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>
  </NuxtLayout>
</template>

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

/**
 * Disable the default layout, the page will use the layout defined with <NuxtLayout />
 * @see https://nuxt.com/docs/guide/directory-structure/layouts#overriding-a-layout-on-a-per-page-basis
 */
definePageMeta({
  layout: false,
});

const i18n = useI18n()
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, Parameters | true>

</script>

<style scoped lang="scss">

</style>
