import { defineStore } from "pinia";
import { ref } from "vue";


const products = [
    {name: "product name", price: 342432},
    {name: "product name", price: 342432},
    {name: "product name", price: 342432},
    {name: "product name", price: 342432},
    {name: "product name", price: 342432},
]

// type CategoryProducts = {}

export const useCategoryStore = defineStore('category', () => {
    const idCategory = ref(0)
    const categoryProducts = ref(products)


    function setCategoryID(id: number) {
        idCategory.value = id
    }

    async function getCategoryProducts() {
        return new Promise<typeof products>((resolve) => {
            setTimeout(() => {
                // console.log('Fetching products from category id: ', idCategory.value);
                resolve(categoryProducts.value)
            }, 2000 * Math.random())
        })
    }
    return {
        idCategory,
        getCategoryProducts,
        setCategoryID
    }
})



