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

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

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

                  <UiInputNumber
                    v-if="parameters.notifyAdministrationAbsence"
                    v-model="parameters.numberConsecutiveAbsences"
                    field="numberConsecutiveAbsences"
                    label="numberConsecutiveAbsences"
                    :rules="getAsserts('numberConsecutiveAbsences')"
                  />
                </div>
              </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>
