<template>
  <LayoutContainer>
    <UiLoadingPanel v-if="pending" />
    <UiForm v-else :model="Parameters" :entity="parameters">
      <v-row>
        <v-col cols="6">
          <UiInputCheckbox
            v-model="parameters.sendAttendanceEmail"
            field="sendAttendanceEmail"
            label="sendAttendanceEmail"
          />

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

          <UiInputCheckbox
            v-model="parameters.notifyAdministrationAbsence"
            field="notifyAdministrationAbsence"
          />
        </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 { AsyncData } from '#app'

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>
