<template>
  <LayoutContainer>
    <UiLoadingPanel v-if="pending" />
    <UiForm
        v-else
        :model="Parameters"
        :entity="parameters"
        action-position="bottom"
    >
      <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"
          />

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

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

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

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

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

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>
