<script setup>
import { useI18n } from 'vue-i18n';
import VnSearchbar from 'components/ui/VnSearchbar.vue';

const { t } = useI18n();

const exprBuilder = (param, value) => {
    switch (param) {
        case 'name':
            return {
                name: { like: `%${value}%` },
            };
        case 'code':
            return {
                code: { like: `%${value}%` },
            };
        case 'agencyModeFk':
            return {
                agencyModeFk: value,
            };
        case 'search':
            return /^\d+$/.test(value) ? { id: value } : { name: { like: `%${value}%` } };
    }
};
</script>

<template>
    <VnSearchbar
        data-key="Zones"
        url="Zones"
        :filter="{
            include: { relation: 'agencyMode', scope: { fields: ['name'] } },
        }"
        :expr-builder="exprBuilder"
        :label="t('list.searchZone')"
        :info="t('list.searchInfo')"
        custom-route-redirect-name="ZoneSummary"
    />
</template>
