<script setup>
import { onMounted, onUnmounted } from 'vue';
import { useI18n } from 'vue-i18n';
import RightMenu from 'src/components/common/RightMenu.vue';
import VnTable from 'components/VnTable/VnTable.vue';
import EntryLatestBuysFilter from './EntryLatestBuysFilter.vue';
import { useStateStore } from 'stores/useStateStore';
const stateStore = useStateStore();
const { t } = useI18n();
import { toDate } from 'src/filters';
import VnImg from 'src/components/ui/VnImg.vue';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';

const columns = [
    {
        align: 'center',
        label: t('entry.latestBuys.tableVisibleColumns.image'),
        name: 'image',
        columnField: {
            component: VnImg,
            attrs: (id) => {
                return {
                    id,
                    width: '50px',
                };
            },
        },
        columnFilter: false,
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.itemFk'),
        name: 'itemFk',
        isTitle: true,
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.packing'),
        name: 'packing',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.grouping'),
        name: 'grouping',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.quantity'),
        name: 'quantity',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.description'),
        name: 'description',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.size'),
        name: 'size',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.tags'),
        name: 'tags',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.type'),
        name: 'type',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.intrastat'),
        name: 'intrastat',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.origin'),
        name: 'origin',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.weightByPiece'),
        name: 'weightByPiece',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.isActive'),
        name: 'isActive',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.family'),
        name: 'family',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.entryFk'),
        name: 'entryFk',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.buyingValue'),
        name: 'buyingValue',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.freightValue'),
        name: 'freightValue',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.comissionValue'),
        name: 'comissionValue',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.packageValue'),
        name: 'packageValue',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.isIgnored'),
        name: 'isIgnored',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.price2'),
        name: 'price2',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.price3'),
        name: 'price3',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.minPrice'),
        name: 'minPrice',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.ektFk'),
        name: 'ektFk',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.weight'),
        name: 'weight',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.packagingFk'),
        name: 'packagingFk',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.packingOut'),
        name: 'packingOut',
    },
    {
        align: 'left',
        label: t('entry.latestBuys.tableVisibleColumns.landing'),
        name: 'landing',
        component: 'date',
        columnField: {
            component: null,
        },
        format: (row, dashIfEmpty) => dashIfEmpty(toDate(row.landing)),
    },
];

onMounted(async () => {
    stateStore.rightDrawer = true;
});

onUnmounted(() => (stateStore.rightDrawer = false));
</script>

<template>
    <RightMenu>
        <template #right-panel>
            <EntryLatestBuysFilter data-key="LatestBuys" />
        </template>
    </RightMenu>
    <VnSubToolbar />
    <VnTable
        ref="tableRef"
        data-key="LatestBuys"
        url="Buys/latestBuysFilter"
        order="id DESC"
        :columns="columns"
        redirect="entry"
        auto-load
        :right-search="false"
    />
</template>

<i18n>
es:
    Edit buy(s): Editar compra(s)
</i18n>
