<template>
  <div>superadmin email</div>

  <div>
    <LayoutContainer>
      <UiLoadingPanel v-if="pending" />

      <div v-else>
        <UiForm
          ref="form"
          :model="AdminAccess"
          :entity="adminAccess"
          :submitActions="submitActions"
        >
          <UiInputText
            field="label"
            v-model="adminAccess.email"
            :rules="rules()"
          />
        </UiForm>
      </div>
    </LayoutContainer>
  </div>
</template>

<script setup lang="ts">
import { useEntityFetch } from '~/composables/data/useEntityFetch'
import { useAccessProfileStore } from '~/stores/accessProfile'
import AdminAccess from '~/models/Access/AdminAccess'

const { fetch } = useEntityFetch()

const accessProfile = useAccessProfileStore()
if (accessProfile.id === null) {
  throw new Error('Missing access profile id')
}

const { data: adminAccess, pending } = fetch(AdminAccess, accessProfile.id)

const i18n = useI18n()

const rules = () => [
  (timing: number) =>
    (timing !== null && timing > 0) || i18n.t('value_need_to_be_bigger_than_0'),
]
</script>
