<script setup>
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import VnInput from 'components/common/VnInput.vue';
import FetchData from 'components/FetchData.vue';
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
import VnSelect from 'components/common/VnSelect.vue';

const { t } = useI18n();
const props = defineProps({
    dataKey: {
        type: String,
        required: true,
    },
    exprBuilder: {
        type: Function,
        default: null,
    },
});

const agencies = ref([]);
</script>

<template>
    <FetchData url="agencies" @on-fetch="(data) => (agencies = data)" auto-load />
    <VnFilterPanel
        :data-key="props.dataKey"
        :search-button="true"
        :hidden-tags="['search']"
        search-url="table"
    >
        <template #tags="{ tag }">
            <div class="q-gutter-x-xs">
                <strong>{{ t(`filterPanel.${tag.label}`) }}: </strong>
                <span>{{ tag.value }}</span>
            </div>
        </template>
        <template #body="{ params, searchFn }">
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('filterPanel.name')"
                        v-model="params.name"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnSelect
                        :label="t('filterPanel.agencyModeFk')"
                        v-model="params.agencyModeFk"
                        :options="agencies"
                        option-value="id"
                        option-label="name"
                        @update:model-value="searchFn()"
                        dense
                        outlined
                        rounded
                    >
                    </VnSelect>
                </QItemSection>
            </QItem>
        </template>
    </VnFilterPanel>
</template>
