<template>
  <div>
    <LayoutCommonSection v-if="organizationProfile.isSchool">
      <h4>{{ $t('alert_configuration') }}</h4>
      <UiFormEdition :model="Parameters" :id="organizationProfile.parametersId">
        <template #default="{ entity : parameters }">
          <div v-if="parameters">
            <v-row>
              <v-col cols="12">
                <UiInputCheckbox
                  v-model="parameters.sendAttendanceEmail"
                  field="sendAttendanceEmail"
                  label="sendAttendanceEmail"
                />

                <UiInputCheckbox
                  v-model="parameters.sendAttendanceSms"
                  field="sendAttendanceSms"
                />

                <UiInputCheckbox
                  v-model="parameters.notifyAdministrationAbsence"
                  field="notifyAdministrationAbsence"
                />

                <UiInputNumber
                  v-if="parameters.notifyAdministrationAbsence"
                  v-model="parameters.numberConsecutiveAbsences"
                  field="numberConsecutiveAbsences"
                  :rules="getAsserts('numberConsecutiveAbsences')"
                />
              </v-col>
            </v-row>
          </div>
        </template>
      </UiFormEdition>
    </LayoutCommonSection>

    <LayoutCommonSection>
      <LayoutParametersEntityTable
        :model="AttendanceBookingReason"
        :title="$t('attendanceBookingReasons')"
        :columns-definitions="[{ property: 'reason' }]"
      />
    </LayoutCommonSection>
  </div>
</template>
<script setup lang="ts">
import Parameters from '~/models/Organization/Parameters'
import { useOrganizationProfileStore } from '~/stores/organizationProfile'
import AttendanceBookingReason from '~/models/Booking/AttendanceBookingReason'
import {getAssertUtils} from "~/services/asserts/getAssertUtils";

definePageMeta({
  name: 'parameters_attendances_page',
})

const organizationProfile = useOrganizationProfileStore()

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

const getAsserts = (key) => getAssertUtils(Parameters.getAsserts(), key)

</script>
