<script setup>
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';

import CardSummary from 'components/ui/CardSummary.vue';
import VnLv from 'src/components/ui/VnLv.vue';

import { useArrayData } from 'src/composables/useArrayData';

const route = useRoute();
const { t } = useI18n();

const $props = defineProps({
    id: {
        type: Number,
        default: 0,
    },
});

const { store } = useArrayData('Alias');
const alias = ref(store.data);
const entityId = computed(() => $props.id || route.params.id);
</script>

<template>
    <CardSummary
        ref="summary"
        :url="`MailAliases/${entityId}`"
        @on-fetch="(data) => (alias = data)"
        data-key="MailAliasesSummary"
    >
        <template #header> {{ alias.id }} - {{ alias.alias }} </template>
        <template #body>
            <QCard class="vn-one">
                <QCardSection class="q-pa-none">
                    <router-link
                        :to="{ name: 'AliasBasicData', params: { id: entityId } }"
                        class="header header-link"
                    >
                        {{ t('globals.summary.basicData') }}
                        <QIcon name="open_in_new" />
                    </router-link>
                </QCardSection>
                <VnLv :label="t('mailAlias.id')" :value="alias.id" />
                <VnLv :label="t('mailAlias.description')" :value="alias.description" />
            </QCard>
        </template>
    </CardSummary>
</template>
