<script setup>
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';

import VnSelect from 'components/common/VnSelect.vue';
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnInputDate from 'components/common/VnInputDate.vue';
import VnCurrency from 'src/components/common/VnCurrency.vue';

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

<template>
    <VnFilterPanel :data-key="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 }">
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.supplierRef')"
                        v-model="params.supplierRef"
                        is-outlined
                        lazy-rules
                    >
                        <template #prepend>
                            <QIcon name="vn:client" size="sm"></QIcon>
                        </template>
                    </VnInput>
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.fi')"
                        v-model="params.fi"
                        is-outlined
                        lazy-rules
                    >
                        <template #prepend>
                            <QIcon name="badge" size="sm"></QIcon>
                        </template>
                    </VnInput>
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnSelect
                        v-model="params.supplierFk"
                        url="Suppliers"
                        :fields="['id', 'nickname']"
                        :label="t('params.supplierFk')"
                        option-value="id"
                        option-label="nickname"
                        :options="suppliers"
                        dense
                        outlined
                        rounded
                    >
                    </VnSelect>
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.account')"
                        v-model="params.account"
                        is-outlined
                        lazy-rules
                    >
                        <template #prepend>
                            <QIcon name="person" size="sm" />
                        </template>
                    </VnInput>
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnCurrency v-model="params.amount" is-outlined />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInputDate :label="t('From')" v-model="params.from" is-outlined />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInputDate :label="t('To')" v-model="params.to" is-outlined />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInputDate
                        :label="t('Issued')"
                        v-model="params.issued"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem class="q-mb-md">
                <QItemSection>
                    <QCheckbox
                        :label="t('params.isBooked')"
                        v-model="params.isBooked"
                        @update:model-value="searchFn()"
                        toggle-indeterminate
                    />
                </QItemSection>
            </QItem>
            <QExpansionItem :label="t('More options')" expand-separator>
                <QItem>
                    <QItemSection>
                        <VnInput
                            :label="t('params.serialNumber')"
                            v-model="params.serialNumber"
                            is-outlined
                            lazy-rules
                        >
                            <template #prepend>
                                <QIcon name="badge" size="sm"></QIcon>
                            </template>
                        </VnInput>
                    </QItemSection>
                </QItem>
                <QItem>
                    <QItemSection>
                        <VnInput
                            :label="t('params.serial')"
                            v-model="params.serial"
                            is-outlined
                            lazy-rules
                        >
                            <template #prepend>
                                <QIcon name="badge" size="sm"></QIcon>
                            </template>
                        </VnInput>
                    </QItemSection>
                </QItem>
                <QItem>
                    <QItemSection>
                        <VnInput
                            :label="t('params.awb')"
                            v-model="params.awbCode"
                            is-outlined
                            lazy-rules
                        >
                            <template #prepend>
                                <QIcon name="badge" size="sm"></QIcon>
                            </template>
                        </VnInput>
                    </QItemSection>
                </QItem>
            </QExpansionItem>
        </template>
    </VnFilterPanel>
</template>

<i18n>
en:
    params:
        search: ID
        supplierRef: Supplier ref.
        supplierFk: Supplier
        fi: Supplier fiscal id
        clientFk: Customer
        amount: Amount
        created: Created
        awb: AWB
        dued: Dued
        serialNumber: Serial Number
        serial: Serial
        account: Account
        isBooked: is booked
        correctedFk: Rectificatives
es:
    params:
        search: Contiene
        supplierRef: Ref. proveedor
        supplierFk: Proveedor
        clientFk: Cliente
        fi: CIF proveedor
        serialNumber: Num. serie
        serial: Serie
        awb: AWB
        amount: Importe
        issued: Emitida
        isBooked: Conciliada
        account: Cuenta
        created: Creada
        dued: Vencida
        correctedFk: Rectificativas
    From: Desde
    To: Hasta
    Amount: Importe
    Issued: Fecha factura
    Id or supplier: Id o proveedor
    More options: Más opciones
</i18n>
