export const useProductsStore = defineStore('products', {
    state: () => {
        return {
            items: [],
            item: null,
            filters: {},
            pages: 0
        }
    },
    actions: {
        async addReminder(id, form) {
            const result = await useFetch(`/api/products/reminder/${id}`, {
                headers: { Authorization: useCookie('token') }, method: 'put', body: form
            })

            return result;

        },
        async addReport(id, form) {
            const body = {
                items: Object.keys(form.items),
                content: form.content
            }
            const result = await useFetch(`/api/products/reports/${id}`, {
                headers: { Authorization: useCookie('token') }, method: 'post', body
            })

            return result;
        },
        async compareSearch(ids, query = "") {
            const { status, data } = await useFetch(`/api/products/comparison/${ids.join('-')}/search?q=${query}`)
            if (status.value == 'success') {
                this.items = data.value
            }
        },
    }
})
