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

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

<template>
    <VnFilterPanel :data-key="dataKey" :search-button="true" search-url="table">
        <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 class="q-my-sm">
                <QItemSection>
                    <VnInput :label="t('FI')" v-model="params.fi" is-outlined>
                        <template #prepend>
                            <QIcon name="badge" size="xs" />
                        </template>
                    </VnInput>
                </QItemSection>
            </QItem>
            <QItem class="q-mb-sm">
                <QItemSection>
                    <VnInput
                        :label="t('customerFilter.filter.name')"
                        v-model="params.name"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem class="q-mb-sm">
                <QItemSection>
                    <VnInput
                        :label="t('customerFilter.filter.socialName')"
                        v-model="params.socialName"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem class="q-mb-sm">
                <QItemSection>
                    <VnSelect
                        url="Workers/activeWithInheritedRole"
                        :filter="{ where: { role: 'salesPerson' } }"
                        auto-load
                        :label="t('Salesperson')"
                        v-model="params.salesPersonFk"
                        @update:model-value="searchFn()"
                        option-value="id"
                        option-label="name"
                        emit-value
                        map-options
                        use-input
                        hide-selected
                        dense
                        outlined
                        rounded
                        :input-debounce="0"
                    />
                </QItemSection>
            </QItem>
            <QItem class="q-mb-sm">
                <QItemSection
                    ><VnSelect
                        url="Provinces"
                        :label="t('Province')"
                        v-model="params.provinceFk"
                        @update:model-value="searchFn()"
                        option-value="id"
                        option-label="name"
                        emit-value
                        map-options
                        hide-selected
                        dense
                        outlined
                        rounded
                        auto-load
                        :input-debounce="0"
                    />
                </QItemSection>
            </QItem>
            <QItem class="q-mb-md">
                <QItemSection>
                    <VnInput :label="t('City')" v-model="params.city" is-outlined />
                </QItemSection>
            </QItem>
            <QSeparator />
            <QExpansionItem :label="t('More options')" expand-separator>
                <QItem>
                    <QItemSection>
                        <VnInput :label="t('Phone')" v-model="params.phone" is-outlined>
                            <template #prepend>
                                <QIcon name="phone" size="xs" />
                            </template>
                        </VnInput>
                    </QItemSection>
                </QItem>
                <QItem>
                    <QItemSection>
                        <VnInput :label="t('Email')" v-model="params.email" is-outlined>
                            <template #prepend>
                                <QIcon name="email" size="sm" />
                            </template>
                        </VnInput>
                    </QItemSection>
                </QItem>
                <QItem>
                    <VnSelect
                        url="Zones"
                        :label="t('Zone')"
                        v-model="params.zoneFk"
                        @update:model-value="searchFn()"
                        option-value="id"
                        option-label="name"
                        emit-value
                        map-options
                        hide-selected
                        dense
                        outlined
                        rounded
                        auto-load
                    />
                </QItem>
                <QItem>
                    <QItemSection>
                        <VnInput
                            :label="t('Postcode')"
                            v-model="params.postcode"
                            is-outlined
                        />
                    </QItemSection>
                </QItem>
            </QExpansionItem>
        </template>
    </VnFilterPanel>
</template>

<i18n>
en:
    params:
        search: Contains
        fi: FI
        salesPersonFk: Salesperson
        provinceFk: Province
        city: City
        phone: Phone
        email: Email
        zoneFk: Zone
        postcode: Postcode
es:
    params:
        search: Contiene
        fi: NIF
        salesPersonFk: Comercial
        provinceFk: Provincia
        city: Ciudad
        phone: Teléfono
        email: Email
        zoneFk: Zona
        postcode: CP
    FI: NIF
    Salesperson: Comercial
    Province: Provincia
    City: Ciudad
    More options: Más opciones
    Phone: Teléfono
    Email: Email
    Zone: Zona
    Postcode: Código postal
</i18n>
