<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.createCourse"
            field="createCourse"
            label="allow_teachers_to_create_courses"
          />

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

          <UiInputCheckbox
            v-model="parameters.consultPedagogicResult"
            field="showAdherentList"
            label="allow_students_to_consult_their_pedagogical_followup"
          />

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

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

          <UiInputCheckbox
            v-model="parameters.allowMembersToChangeGivenNameAndName"
            field="allowMembersToChangeGivenNameAndName"
            label="allow_members_to_change_their_names_and_firstnames"
          />
        </v-col>
      </v-row>
    </UiForm>
  </LayoutContainer>
</template>

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

definePageMeta({
  name: 'parameters_intranet_page',
})

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>
