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

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

<template>
    <VnFilterPanel :data-key="dataKey" :search-button="true" :redirect="false">
        <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 }">
            <QItem>
                <QItemSection>
                    <VnInput
                        v-model="params.search"
                        :label="t('params.search')"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        v-model="params.itemId"
                        :label="t('params.itemId')"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnSelect
                        :label="t('params.buyerId')"
                        v-model="params.buyerId"
                        @update:model-value="searchFn()"
                        url="TicketRequests/getItemTypeWorker"
                        :fields="['id', 'nickname']"
                        sort-by="nickname ASC"
                        option-value="id"
                        option-label="nickname"
                        hide-selected
                        dense
                        outlined
                        rounded
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnSelect
                        :label="t('params.typeId')"
                        v-model="params.typeId"
                        @update:model-value="searchFn()"
                        url="ItemTypes"
                        :include="['category']"
                        :fields="['id', 'name', 'categoryFk']"
                        sort-by="name ASC"
                        option-value="id"
                        option-label="name"
                        hide-selected
                        dense
                        outlined
                        rounded
                    >
                        <template #option="scope">
                            <QItem v-bind="scope.itemProps">
                                <QItemSection>
                                    <QItemLabel>{{ scope.opt?.name }}</QItemLabel>
                                    <QItemLabel caption>{{
                                        scope.opt?.category?.name
                                    }}</QItemLabel>
                                </QItemSection>
                            </QItem>
                        </template>
                    </VnSelect>
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnSelect
                        :label="t('params.categoryId')"
                        v-model="params.categoryId"
                        @update:model-value="searchFn()"
                        url="ItemCategories"
                        :fields="['id', 'name']"
                        sort-by="name ASC"
                        option-value="id"
                        option-label="name"
                        hide-selected
                        dense
                        outlined
                        rounded
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInputDate
                        :label="t('params.from')"
                        v-model="params.from"
                        @update:model-value="searchFn()"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInputDate
                        :label="t('params.to')"
                        v-model="params.to"
                        @update:model-value="searchFn()"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
        </template>
    </VnFilterPanel>
</template>

<i18n>
en:
    params:
        search: General search
        itemId: Item id
        buyerId: Buyer
        typeId: Type
        categoryId: Category
        from: From
        to: To
es:
    params:
        search: Búsqueda general
        itemId: Id Artículo
        buyerId: Comprador
        typeId: Tipo
        categoryId: Reino
        from: Desde
        to: Hasta
</i18n>
