import { defineStore } from 'pinia'
import { useApi } from '@/composables/useApi'

export const useProductStore = defineStore('productStore', {

  state: () => ({
    items: [],
    totalItems: 0,
    //modules: [],
   // pagination: { total: 0, current_page: 1, last_page: 1 },
    currentPage: 1,
    rowsPerPage: 30,

    loading: false,
    error: null,
  }),

  actions: {

    async loadData(page = 1,payload = null) {
        
      try{
        const { data, error, loading, fetchAll, pagination } = useApi('products')
        await fetchAll(page,this.rowsPerPage,payload)
        if (data.value) this.items = data.value;
        if (error.value) this.error = error.value;
        this.loading = loading.value;
        this.totalItems = pagination.total;

      }catch(error){
        console.error(error);
      }
    },


 


  }
})