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

const { t } = useI18n();
defineProps({
    dataKey: {
        type: String,
        required: true,
    },
});

const sectors = ref([]);
const emit = defineEmits(['search']);
</script>

<template>
    <FetchData
        url="Sectors"
        :filter="{ fields: ['id', 'description'] }"
        sort-by="description"
        @on-fetch="(data) => (sectors = data)"
        auto-load
    />
    <VnFilterPanel :data-key="dataKey" :search-button="true" @search="emit('search')">
        <template #tags="{ tag, formatFn }">
            <div class="q-gutter-x-xs">
                <strong>{{ t(`params.${tag.label}`) }}: </strong>
                <span>{{ formatFn(tag.value) }}</span>
            </div>
        </template>
        <template #body="{ params }">
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.code')"
                        v-model="params.code"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnSelect
                        v-model="params.sectorFk"
                        option-value="id"
                        option-label="description"
                        :label="t('params.sectorFk')"
                        dense
                        outlined
                        rounded
                        :options="sectors"
                        use-input
                        input-debounce="0"
                    />
                </QItemSection>
            </QItem>
        </template>
    </VnFilterPanel>
</template>

<i18n>
en:
    params:
        code: Code
        sectorFk: Sector
        search: General Search
es:
    params:
        code: Código
        search: Búsqueda general

</i18n>
