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

import VnCard from 'components/common/VnCard.vue';
import ZoneDescriptor from './ZoneDescriptor.vue';

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

const routeName = computed(() => route.name);
const customRouteRedirectName = computed(() => {
    if (routeName.value === 'ZoneLocations') return null;
    return routeName.value;
});
const searchbarMakeFetch = computed(() => routeName.value !== 'ZoneEvents');
const searchBarDataKeys = {
    ZoneWarehouses: 'ZoneWarehouses',
    ZoneSummary: 'ZoneSummary',
    ZoneLocations: 'ZoneLocations',
    ZoneEvents: 'ZoneEvents',
};
</script>

<template>
    <VnCard
        data-key="Zone"
        :descriptor="ZoneDescriptor"
        :search-data-key="searchBarDataKeys[routeName]"
        :search-custom-route-redirect="customRouteRedirectName"
        :search-redirect="!!customRouteRedirectName"
        :search-make-fetch="searchbarMakeFetch"
        :searchbar-label="t('list.searchZone')"
        :searchbar-info="t('list.searchInfo')"
    />
</template>
