<template>
  <DefaultTable
    ref="tableRef"
    :columns="columns"
    :api-call="getProducts"
    :show-search-field="false"
    description="produtos"
  />
</template>

<script setup>
import { ref } from "vue";
import { formatToBRLCurrency } from "src/helpers/utils";
import { getProducts } from "src/api/product";
import DefaultTable from "src/components/defaults/DefaultTable.vue";

const tableRef = ref(null);

const columns = [
  {
    name:     "name",
    label:    "Produto",
    field:    "name",
    align:    "left",
    sortable: true,
  },
  {
    name:    "price_sale",
    label:   "Preço",
    field:   "price_sale",
    align:   "left",
    format:  (val) => formatToBRLCurrency(val),
  },
  {
    name:     "quantity",
    label:    "Estoque Atual",
    field:    "quantity",
    align:    "center",
    sortable: true,
  },
];

defineExpose({ refresh: () => tableRef.value?.refresh() });
</script>
