<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 FetchData from 'components/FetchData.vue';
import VnInputNumber from 'src/components/common/VnInputNumber.vue';

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

<template>
    <FetchData
        url="SupplierActivities"
        auto-load
        @on-fetch="(data) => (activities = data)"
    />
    <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>
                    <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>
                    <VnSelect
                        v-model="params.supplierFk"
                        url="Suppliers"
                        :fields="['id', 'nickname']"
                        :label="t('params.supplierFk')"
                        option-value="id"
                        option-label="nickname"
                        dense
                        outlined
                        rounded
                        :filter-options="['id', 'name']"
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.supplierRef')"
                        v-model="params.supplierRef"
                        is-outlined
                        lazy-rules
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.fi')"
                        v-model="params.fi"
                        is-outlined
                        lazy-rules
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.serial')"
                        v-model="params.serial"
                        is-outlined
                        lazy-rules
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.account')"
                        v-model="params.account"
                        is-outlined
                        lazy-rules
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInput
                        :label="t('params.awb')"
                        v-model="params.awbCode"
                        is-outlined
                        lazy-rules
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <VnInputNumber
                        :label="t('Amount')"
                        v-model="params.amount"
                        is-outlined
                    />
                </QItemSection>
            </QItem>
            <QItem>
                <QItemSection>
                    <QCheckbox
                        :label="t('invoiceIn.isBooked')"
                        v-model="params.isBooked"
                        @update:model-value="searchFn()"
                        toggle-indeterminate
                    />
                </QItemSection>
                <QItemSection>
                    <QCheckbox
                        :label="t('params.correctingFk')"
                        v-model="params.correctingFk"
                        @update:model-value="searchFn()"
                        toggle-indeterminate
                    />
                </QItemSection>
            </QItem>
        </template>
    </VnFilterPanel>
</template>

<i18n>
en:
    params:
        search: Id or supplier name
        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: Ledger account
        isBooked: is booked
        correctedFk: Rectified
        issued: Issued
        to: To
        from: From
        awbCode: AWB
        correctingFk: Rectificative
        supplierActivityFk: Supplier activity
es:
    params:
        search: Id o nombre proveedor
        supplierRef: Ref. proveedor
        supplierFk: Proveedor
        clientFk: Cliente
        fi: CIF proveedor
        serialNumber: Num. serie
        serial: Serie
        awb: AWB
        amount: Importe
        issued: Emitida
        isBooked: Contabilizada
        account: Cuenta contable
        created: Creada
        dued: Vencida
        correctedFk: Rectificada
        correctingFk: Rectificativa
        supplierActivityFk: Actividad proveedor
        from: Desde
        to: Hasta
    From: Desde
    To: Hasta
    Amount: Importe
    Issued: Fecha factura
    Id or supplier: Id o proveedor
    More options: Más opciones
</i18n>
