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

const { t } = useI18n();
const stateStore = useStateStore();

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':
            if (value) {
                if (!isNaN(value)) {
                    return { id: value };
                } else {
                    return {
                        name: {
                            like: `%${value}%`,
                        },
                    };
                }
            }
    }
};
</script>

<template>
    <VnSearchbar
        data-key="ZoneList"
        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"
    />
    <QDrawer v-model="stateStore.leftDrawer" show-if-above :width="256">
        <QScrollArea class="fit text-grey-8">
            <LeftMenu />
        </QScrollArea>
    </QDrawer>
    <QPageContainer>
        <RouterView></RouterView>
    </QPageContainer>
</template>
