<script setup>
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import CardSummary from 'components/ui/CardSummary.vue';
import VnLv from 'components/ui/VnLv.vue';
import VnUserLink from 'components/ui/VnUserLink.vue';

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

const entityId = computed(() => $props.id || route.params.id);

const filter = {
    include: [
        {
            relation: 'worker',
            scope: {
                fields: ['id'],
                include: {
                    relation: 'user',
                    scope: { fields: ['nickname'] },
                },
            },
        },
        { relation: 'parking' },
    ],
};
</script>

<template>
    <div class="q-pa-md">
        <CardSummary
            ref="summary"
            :url="`Shelvings/${entityId}`"
            :filter="filter"
            data-key="ShelvingSummary"
        >
            <template #header="{ entity }">
                <div>{{ entity.code }}</div>
            </template>
            <template #body="{ entity }">
                <QCard class="vn-one">
                    <RouterLink
                        class="header header-link"
                        :to="{ name: 'ShelvingBasicData', params: { id: entityId } }"
                    >
                        {{ t('globals.pageTitles.basicData') }}
                        <QIcon name="open_in_new" />
                    </RouterLink>
                    <VnLv :label="t('shelving.summary.code')" :value="entity.code" />
                    <VnLv
                        :label="t('shelving.summary.parking')"
                        :value="entity.parking?.code"
                    />
                    <VnLv
                        :label="t('shelving.summary.priority')"
                        :value="entity.priority"
                    />
                    <VnLv v-if="entity.worker" :label="t('shelving.summary.worker')">
                        <template #value>
                            <VnUserLink
                                :name="entity.worker?.user?.nickname"
                                :worker-id="entity.worker?.id"
                            />
                        </template>
                    </VnLv>
                    <VnLv
                        :label="t('shelving.summary.recyclable')"
                        :value="entity.isRecyclable"
                    />
                </QCard>
            </template>
        </CardSummary>
    </div>
</template>
