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

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

const workers = ref();
</script>

<template>
    <FetchData
        url="Workers/activeWithInheritedRole"
        :filter="{ where: { role: 'salesPerson' } }"
        @on-fetch="(data) => (workers = data)"
        auto-load
    />
    <VnFilterPanel :data-key="props.dataKey" :search-button="true">
        <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, searchFn }">
            <QDate
                v-model="params.created"
                @update:model-value="searchFn()"
                dense
                flat
                minimal
            >
            </QDate>
            <QSeparator />
            <QItem>
                <QItemSection v-if="!workers">
                    <QSkeleton type="QInput" class="full-width" />
                </QItemSection>
                <QItemSection v-if="workers">
                    <QSelect
                        :label="t('User')"
                        v-model="params.userFk"
                        @update:model-value="searchFn()"
                        :options="workers"
                        option-value="id"
                        option-label="name"
                        emit-value
                        map-options
                        use-input
                        :input-debounce="0"
                    />
                </QItemSection>
            </QItem>
        </template>
    </VnFilterPanel>
</template>

<i18n>
en:
    params:
        search: Contains
        userFk: User
        created: Created
es:
    params:
        search: Contiene
        userFk: Usuario
        created: Creada
    User: Usuario
</i18n>
