<script setup>
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import VnTable from 'components/VnTable/VnTable.vue';
import VnSearchbar from 'components/ui/VnSearchbar.vue';
import RightMenu from 'components/common/RightMenu.vue';
import SupplierListFilter from './SupplierListFilter.vue';

const { t } = useI18n();
const tableRef = ref();

const columns = computed(() => [
    {
        align: 'left',
        label: t('supplier.list.tableVisibleColumns.id'),
        name: 'id',
        isTitle: true,
    },
    {
        align: 'left',
        label: t('supplier.list.tableVisibleColumns.name'),
        name: 'socialName',
        create: true,
        component: 'input',
        columnField: {
            component: null,
        },
    },
    {
        align: 'left',
        label: t('supplier.list.tableVisibleColumns.nif'),
        name: 'nif',
        component: 'input',
        columnField: {
            component: null,
        },
    },
    {
        align: 'left',
        label: t('supplier.list.tableVisibleColumns.nickname'),
        name: 'alias',
        component: 'input',
        columnField: {
            component: null,
        },
    },
    {
        align: 'left',
        label: t('supplier.list.tableVisibleColumns.account'),
        name: 'account',
        component: 'input',
        columnField: {
            component: null,
        },
    },
    {
        align: 'left',
        label: t('supplier.list.tableVisibleColumns.payMethod'),
        name: 'payMethod',
        component: 'select',
        attrs: {
            url: 'payMethods',
            fields: ['id', 'name'],
        },
        columnField: {
            component: null,
        },
    },
    {
        align: 'left',
        label: t('supplier.list.tableVisibleColumns.payDay'),
        name: 'payDat',
        component: 'input',
        columnField: {
            component: null,
        },
    },
]);
</script>

<template>
    <VnSearchbar data-key="SuppliersList" :limit="20" :label="t('Search suppliers')" />
    <RightMenu>
        <template #right-panel>
            <SupplierListFilter data-key="SuppliersList" />
        </template>
    </RightMenu>
    <VnTable
        ref="tableRef"
        data-key="SuppliersList"
        url="Suppliers/filter"
        save-url="Suppliers/crud"
        redirect="supplier"
        :create="{
            urlCreate: 'Suppliers/newSupplier',
            title: t('Create Supplier'),
            onDataSaved: ({ id }) => tableRef.redirect(id),
            formInitialData: {},
        }"
        order="id ASC"
        :columns="columns"
        auto-load
        :right-search="false"
        :use-model="true"
    />
</template>

<i18n>
en:
    Search suppliers: Search suppliers

es:
    Search suppliers: Buscar proveedores
</i18n>
